I have a list view whose data I receive from an api call say in the order
1
2
3
4
5
After I click on one item say 3, I make the api call that gives the data in the order
3
1
2
4
5
and I need to display the same. But my list view currently populates like
3
1
3
4
5
I checked the log that displays the listview item data and it prints in the correct order
ListView {
id: contactListView
dataModel: contactsData
listItemComponents: [
ListItemComponent
{
id: homeListComponent
type: "item"
CustomListItemHomePage
{
id: listCell
background: ListItemData.colors
text: ListItemData.name;
onClicked: {
listCell.ListItem.view.fetchListFromLV();
}
}
}
]
function fetchListFromLV()
{
//some codes that makes the api call here
}
}
attachedObjects: [
GroupDataModel {
id: contactsData
sortingKeys: [ "last" ]
grouping: ItemGrouping.None
},
Communication {
id: requestPost
onComplete: {
//gets the api call response here
var response = JSON.parse(info);
console.log(response);
if (response.hasOwnProperty('contacts'))
{
contactsData.clear();
//contactListView.dataModelChanged(contactsData);
var contacts = response["contacts"];
for (var cntNames in contacts)
{
contactsData.insert({
name: contacts[cntNames].toString(),
last: contactsData.size(),
colors: setBgColor(contactsData.size())
})
}
}
//This log prints data in correct order i.e 3 1 2 4 5 but the data displayed in list view prints in wrong order 3 1 3 4 5
for (var i=0;i<contactsData.size();i++)
{
console.log(contactsData.data([i]).name);
}
}
]