Reputation: 7973
I want to add object dynamically to the ListModel. But I need to append the object only if it does not exist in the model.
I gone through the Documentation I couldn't find any methods for this. Is there any other ways to check this
Upvotes: 0
Views: 1829
Reputation: 11
The ListModel method get(index) enables you to access each element. It also has a property count, which tells you how many elements are in it. So, something like this:
function appendIfNotExist(objectToAppend) {
for (var i = 0; i < myListModel.count; i++) {
if (myListModel.get(i) == objectToAppend) {
return
}
}
ListModel.append(objectToAppend)
}
Upvotes: 0