Arash Badie Modiri
Arash Badie Modiri

Reputation: 179

finding a specific element of a ListModel based on its properties in QtQuick 2.0

I have a ListModel with an objectId role (integer and unique). I want to query the model to find other properties of an element with a specific objectId. How can I do that?

Upvotes: 3

Views: 2299

Answers (1)

koopajah
koopajah

Reputation: 25642

You can loop other your model to retrieve each element one by one searching for your objectId

for(var i = 0; i < myModel.count; i++) {
  var elemCur = myModel.get(i);
  if(searchedId == elemCur.objectId) {
    console.log("Found it at index : ", i);
  }
}

Upvotes: 3

Related Questions