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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Carrier: Koodo

Autopopulate non-existent data in listview

I'm downloading data through a rest call in the form of json and sometimes a few data items are incomplete.For example lets says I get this data:

 

[
{"name":"Andrew","email":"andrew@test.com"},
{"name":"Haley","email":"haley@test.com"},
{"name":"Mark"},
{"name":"Stephanie","email":"stephanie@test.com"}
]

 

For some weird reason when I put this data into a ListView, the datamodel will automatically fill in non-existent data with data from another item (i.e. "Mark" has no email in the data, but the ListView will show his email as "haley@test.com"). Has anyone else experienced this problem? And is there a way to fix it?

Please use plain text.
Regular Contributor
CrozyBB
Posts: 83
Registered: ‎07-19-2012
My Carrier: Koodo

Re: Autopopulate non-existent data in listview

I was thinking I could also go through and populate non-existent values by doing something like the following:

onDataLoaded: {
    dataModel.clear();

    for (var i=0;i<data.length;i++)
    {
        if (data[i].contains("email") == false)
        {
            data[i].insert({"email":"no email available"});
        }
    }
    dataModel.insertList(data);
}

 however this doesn't work. I'm thinking is has something to do with .contains().

Please use plain text.