Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Mercurial
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y

Accessing listView's model from ListViewComponent

I have Marked and Unmarked items in my listview. I present each type with a different ListViewComponent since I need to have a different ActionSet for marked and unmarked components (with 'Mark' and 'Unmark' actions). Now, I'd like to access the model from the ListItemComponent as well as call some functions on the attached Bookmarker:

 

Page {

    attachedObjects: [
        Bookmarker {
            id: bookmarker
        }
    ]

    ListView{
       id: listView
listItemComponents: [
 ListItemComponent {
                    id: unmarkedComponent
                    type: 'unmarked_item'
                    GameItem {
                        contextActions: [
                            ActionSet {
                                ActionItem {
                                    title: "Set as bookmark"
                                    onTriggered: {
                                        bookmarker.bookmarkShow(ListItemData.showID)
                                    }
                                }
                            }

                        ]
                    }
                }
]
}
}

 I have a couple of more ListItemComponents I didn't paste because it's not really necessery. GameItem is a container I'm reusing in different components. Now, I can't access neither bookmarker, nor listView from ListItemComponent. The bookmaker is successfuly attached ( I can call it's INVOKABLE methods from listView).

1.How can I change the dataModel inside the ListViewComponent?

2.Why can't I access objects outside the ListItemComponent scope from the onTriggered handler? 

3.What happens if I change the model which determines the type of the ListViewComponent? Can I somehow reload the data and get the appropriate item ( if I change marked -> unmarked, I need to reload the component)?

Please use plain text.
Developer
CapQNX
Posts: 111
Registered: ‎01-11-2013
My Device: BlackBerry Curve
My Carrier: Docomo

Re: Accessing listView's model from ListViewComponent

Hello friend,

    As per my thinking to access any item from outside to listitem component.above listcomponent create function that should return whatever you want to return.Now just return the reference of your datamodel in function and call this function inside the listitem component bu creating id of your container in your case GameItem's id.and call the it like yourGameItemid.listItemData.view.yourfunction.anymethodyou want to call.e.g.GameItemid.listitemdata.view.

Page {

    attachedObjects: [
        Bookmarker {
            id: bookmarker
        }
    ]

    ListView{
       id: listView
listItemComponents: [
 ListItemComponent {
                    id: unmarkedComponent
                    type: 'unmarked_item'
function myModel()
{
return yourdatamodelref;
} GameItem {
id:mygameid contextActions: [ ActionSet { ActionItem { title: "Set as bookmark" onTriggered: { bookmarker.bookmarkShow(ListItemData.showID)
mygameid.listItemData.view.myModel().childCount(); //you can change datamodel like this; } } } ] } } ] } }
hope it helps..

 

Please use plain text.
Contributor
Mercurial
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y

Re: Accessing listView's model from ListViewComponent

It helped. Actually it is:

mygameid.ListItem.view

 which references the ListView, so the function should be in that scope.

 

3. I'm now trying to reload(redraw) a component with no luck, since I changed the type. I'm trying to handle it in onTypeChanged.

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Accessing listView's model from ListViewComponent

see
http://supportforums.blackberry.com/t5/Native-Development-Knowledge/How-to-access-qml-properties-fro...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
Mercurial
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y

Re: Accessing listView's model from ListViewComponent

Thank you, I have successfully solved that issue. The only problem that remains is reloading the component when type is changed.

Please use plain text.