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
Highlighted
Developer
Posts: 404
Registered: ‎04-04-2012
My Device: BlackBerry Z30/Z10/Z10LE/Q10/PlayBook
Accepted Solution

contextAction to push a page passing datamodel.data

Sorry if this has been asked before. Searched and couldn't find a solution for the problem I am having.

 

I am trying to push a page to display data from a dataModel. I am trying to do this from a context menu. From my searched, I learned about creating a function to handle the scope issues. But I have tired and haven't found a solution to the data. Any solutions?

 

            ListView {
                id: sitesList
                topMargin: 50
                dataModel: sitesModel

                listItemComponents: ListItemComponent {
                    type: "item"

                    StandardListItem {
                        id: siteListItem
                        imageSource: "asset:///images/" + ListItemData.FuelBrand + ".png"
                        title: ListItemData.Location_Desc
                        description: qsTr("%1, %2, %3").arg(ListItemData.Site_Address1).arg(ListItemData.City_id).arg(ListItemData.Province_id)
                        contextActions: [
                            ActionSet {
                                title: "Station"
                                ActionItem {
                                    title: qsTr("Services")
                                    imageSource: "asset:///icons/ic_view_details.png"
                                    onTriggered: {
                                        siteListItem.ListItem.view.pushDetailsPage();
                                    }
                                }
                            }
                        ]
                    }
                }

		function pushDetailsPage() {
                    // Trying to get the data here and pass to page.
                    var page = sitesPage.createObject();
                    navPane.push(page);
                }
            }

 

Developer
Posts: 62
Registered: ‎11-30-2012
My Device: BlackBerry Z10
My Carrier: Telus

Re: contextAction to push a page passing datamodel.data

If you use slog2info, what error do you get?

 

__________________________________________________________

If my post helped, click the like button!

Developer of Reader|YC , an open source Hackernews client
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: contextAction to push a page passing datamodel.data

[ Edited ]

I did something like this :

 

onTriggered: {
    var page = sitesPage.createObject();

	Qt.locationDesc = siteListItem.ListItem.data.Location_Desc;
	Qt.description = siteListItem.ListItem.data.description;
   
   navPane.push(page);
}

 And in the sitesPage, create two page properties and this code in onCreateionCompleted:

sitesPage
   property string locationDesc
   property string description

onCreationCompleted: {
  locationDesc = Qt.locationDesc;
  description = Qt.description;
  
  ...
}

 

BlackBerry Development Advisor
Posts: 57
Registered: ‎10-04-2012
My Device: developer
My Carrier: none

Re: contextAction to push a page passing datamodel.data

There are a few strategies to successfully achieve what you want. I think this is the simplest way.

in the sites page, setup the properties like you have:

Page {
    property string locationDesc
    property string description
}

And, in the ListView page:

...
    ActionItem {
        title: qsTr("Services")
        imageSource: "asset:///icons/ic_view_details.png"
        onTriggered: {
            siteListItem.ListItem.view.pushDetailsPage(ListItemData);
        }
    }
...
function pushDetailsPage(data) {
    // Trying to get the data here and pass to page.
    var page = sitesPage.createObject();
    page.locationDesc = data.Location_Desc
    page.description = data.description
    navPane.push(page);
}

If you need to do complex initialization in the sites page when you set those properties, make an initialization function on the sites page that takes the data parameter and call it in pushDetailsPage.