0
votes

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

1
You can loop over the ListModel. However it is not designed for that. You should consider implementing some kind of SetModel yourself in C++.derM
You can relate to ListModel as array of elements with ListModel.count and ListModel.get()folibis

1 Answers

0
votes

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)
}