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
Developer
Posts: 48
Registered: ‎06-24-2010
My Device: Storm 2
My Carrier: Orange
Accepted Solution

Access ListView model from ListItemComponent context action onTriggered

Consider following piece of code:

 

            ListView {
                id: listView
                dataModel: model
                listItemComponents: ListItemComponent {
                    content: StandardListItem {
                        title: ListItemData.name
                        contextActions: ActionSet {                          
                            actions: ActionItem {                        
                                title: "Delete"
                                
                                onTriggered: {
                                    //ListItem.view.model .... doesn't work
                                }
                            }
                        }
                    }
                }
             }
        }

 

When user chooses to delete a row, I'd like to access listview model and remove given row. But I can't get hold of model (for now it's defined as attached property). 

 

Docs say:

 

ListItem.view - The ListView in which this item is visible. The item is in a context separate from the ListView, so any symbols from the ListView context that are to be accessible from items must be placed as dynamic properties on the ListView

 But to be honest I don't understand what I need to do to make it work (ie. be able to access parent listView.

 

Any help would be greatly appreciated.

 

Oh, I'd like to do this without falling back to C++. I know how to solve this with c++.

 

Thanks

Highlighted
Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Access ListView model from ListItemComponent context action onTriggered

you should reference ListItem to your ListItemComponent:

myItem.ListItem.view.dataModel

 

Developer
Posts: 48
Registered: ‎06-24-2010
My Device: Storm 2
My Carrier: Orange

Re: Access ListView model from ListItemComponent context action onTriggered

OK, now I understand. Thanks!

 

If anyone stumbles upon this: 

 

myItem should be id of what you define as content of ListItemComponent, for ex:

 

ListView {
    id: listView
    dataModel: model
    listItemComponents: ListItemComponent {
        content: StandardListItem {
            id: myComponent
            title: ListItemData
            contextActions: ActionSet {
                actions: [
                    DeleteActionItem {
                        title: "Delete"
                        onTriggered: {
                            myComponent.ListItem.view.dataModel.clear()                            
                        }
                    }
                ]
            }
        }
    }
}