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
Posts: 13
Registered: ‎02-08-2013
My Device: Z10
My Carrier: Rogers
Accepted Solution

ListView With Context Actions

Could anyone give me a sample code on how to pass data from my listitem to a "comment" context actions?

 

I have my Listview working and I am able to see the context actions when I long press any of the listitems. Once I select the "Comment" context actions, I want the indexPath so that I can get the data from the selected listItem which initially triggered the context actions.

 

Below logic gives an error saying "can't find reference to dataModel".  I also tried to call the javascript function where I cant reference indexPath. Any help on this? 

 

contextActions: [
        ActionSet {
             actions: [
                  ActionItem {
                          title: "Comment"
                          imageSource: "images/icon.png"
                          onTriggered: {
                                     var select = dataModel.data(indexPath)
                          }
                   }
             ]
       } 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

[ Edited ]

This is correct as long as you have defined dataModel in your ListView.

 

e.g.

 

			    dataModel: XmlDataModel {
			        source: "models/images.xml"
			    }

 

If you are trying to access from a ListItemComponant then you can access as such,

 

ListItemComponent {

	StandardListItem {

	    id: folderItem

	    contextActions: [
	        ActionSet {
	            title: "Folder action"

	            ActionItem {
	                title: qsTr("Rename Folder")
	                onTriggered: {
	                    // access by dataModel by prefix folderItem.ListItem.view.dataModel
	                }
	            }

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 13
Registered: ‎02-08-2013
My Device: Z10
My Carrier: Rogers

Re: ListView With Context Actions

[ Edited ]

Thanks for the quick reply.
I have tried ur code before. How do I print my indexPath using "folderItem.ListItem.view.dataModel" ???

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

Assuming you have subclassed a datamodel like so,

 

class FolderModel : public GroupDataModel {

 then just add the following to your application class,

 

    qmlRegisterType<FolderModel>("custom.lib", 1, 0, "FolderModel");

 and import the custom.lib library into your QML file.

 

Can I recommend reading this for how to integrate C++ and QML,

 

http://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

[ Edited ]

[edit] It's a bit hard to answer your questions if you keep editing and swapping what the question actually is!

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 13
Registered: ‎02-08-2013
My Device: Z10
My Carrier: Rogers

Re: ListView With Context Actions

I have already imported the libarary into my QML file.
Please note I am able to see the indePath by using onTriggered signal. I am not able to see the indexPath if I use ContextActions

onTriggered: {
var selectedItem = dataModel.data(indexPath);
var page = webView.createObject();
page.webUrl = selectedItem.Link;
navigationPane.push(page);
}
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

My answers don't make any sense if you change the question while I'm writing them, I'm going to wait 10 minutes and see if this question is stable before answering.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

[ Edited ]

Is the ContextMenu in your ListView or ListItemComponent?

 

Note you won't have an selected indexPath until the onTriggered signal has been sent.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Contributor
Posts: 13
Registered: ‎02-08-2013
My Device: Z10
My Carrier: Rogers

Re: ListView With Context Actions

Sorry for editing my question. Contextmenu is inside my ListItemComponent.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: ListView With Context Actions

Okay reading my note above are you trying to access indexPath outside of the onTriggered signal?

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.