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
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A
My Carrier: Koodo
Accepted Solution

Using qml basic type variant for a map of key-value pairs

I have data in my app in the form of  a set of json key-value pairs which is accessed through the DataSource construct in qml. I would like to put this in a property variant which can be accessed from a number of different UI objects (labels, lists, text fields, etc.). Here is what I have...

Page {
    property variant item
    Container {
         Label {
	       id: testLabel  
	 }
.
.
.

 And this is the json file with the data

{
    "message":"Request Successful",
    "data":{
	"id":52,
    },
    "date":"2012-12-17 12:47:28"},
    "status":"success"
}

 Yet if I go with something like the following I get the text to show in the label

       DataSource{ 
               id: dataSource   
               source: "models/test.json"
	       onDataLoaded: {  
	             testLabel.text = data.message
	      } 
       }

According to the this page a qml variant type should have no problem holding a set of key-value pairs. Does anyone know why this is happening? Am I missing something obvious?

 

Please use plain text.
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A
My Carrier: Koodo

Re: Using qml basic type variant for a map of key-value pairs

Nevermind :smileyembarrassed: I needed to declare the property variant within the NavigationPane section not the Page section *facepalm*

Please use plain text.
New Developer
shmily-lu
Posts: 14
Registered: ‎07-17-2012
My Device: 8900 and playbook
My Carrier: CHINA MOBILE

Re: Using qml basic type variant for a map of key-value pairs

thanks for sharing

Please use plain text.
Trusted Contributor
MXZ
Posts: 104
Registered: ‎11-28-2012
My Device: PlayBook
My Carrier: 3 it

Re: Using qml basic type variant for a map of key-value pairs

Welcome :smileyhappy:
Please use plain text.