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
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
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)
}
ListModel
. However it is not designed for that. You should consider implementing some kind ofSetModel
yourself in C++. – derMListModel
as array of elements with ListModel.count and ListModel.get() – folibis