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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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

Developer
Posts: 79
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()                            
                        }
                    }
                ]
            }
        }
    }
}