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
New Developer
Posts: 6
Registered: ‎03-03-2014
My Device: BlackBerry Z10
Accepted Solution

JSON Listview Listing Wrong Data

Hi all,

 

Quick question here I've been working on all day but can't seem to figure out. My app fetches JSON data from an online database. The JSON data looks like this:

 

{
  "legislations": [
    {
      "databaseId": "cas",
      "legislationId": "rsc-1985-c-a-1",
      "title": "Access to Information Act",
      "citation": "RSC 1985, c A-1",
      "type": "STATUTE"
    },

(...)

 For some reason, in the ListView, the 'citation' key is shown (eg, for this entry, 'RSC 1985, c A-1' will be displayed), not title. I'm confused because I don't even mention the word 'citation' in my code!

 

Even more confusingly, I'm able to sort the keys by title, so the list is in correct alphabetical order, but I just can't get the titles to show up!

Here's my code so far:

 

(...)

ListView {
            id: browseLegList
            dataModel: legBrowsDataModel 
            	
            listItemComponents: [
            	ListItemComponent {
            		type: "title"
            		Container {
            		leftPadding: 30
            		preferredWidth: 768
            		preferredHeight: 100
            
            		layout: DockLayout {}
            		
            		Label {
            			verticalAlignment: VerticalAlignment.Center
            			text: ListItemData // I've also tried ListItemData.title, but no difference
            			multiline: true
            			}
            		
            		Divider {
            			verticalAlignment: VerticalAlignment.Bottom
            			}
            		}
            	}
            ]
        }
    }
    attachedObjects: [
        GroupDataModel {
            id: legBrowsDataModel
            sortingKeys: ["title"]
            grouping: ItemGrouping.ByFirstChar
        },
        DataSource {
            id: legBrowsDataSource
            source: ""
            type: DataSourceType.Json
            
            onDataLoaded: {
                legBrowsDataModel.clear();
                legBrowsDataModel.insertList(data.legislations);
            }
            onError: {
                console.log("JSON load error..." + errorType)
            }
        }   
    ]

(...)

 Does anyone have any suggestions where to go from here?

Thanks!

New Developer
Posts: 8
Registered: ‎07-19-2012
My Device: Z10 LE

Re: JSON Listview Listing Wrong Data

Hi,


Try changing

ListItemComponent {
            		type: "title"
(...)

to

ListItemComponent {
            		type: "item"
(...)

and

Label {
           verticalAlignment: VerticalAlignment.Center
           text: ListItemData
(...)

to

Label {
           verticalAlignment: VerticalAlignment.Center
           text: ListItemData.title
(...)
New Developer
Posts: 6
Registered: ‎03-03-2014
My Device: BlackBerry Z10

Re: JSON Listview Listing Wrong Data

Well, that worked! Is the key the fact that the "type" has to match the "text" variable?

In any regard, thanks so much for your help Issue. Cheers!