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
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A
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?

Regular Contributor
Posts: 83
Registered: ‎07-19-2012
My Device: Bold 9790, Dev Alpha A
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().