Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想将对象动态添加到 ListModel。但是只有当模型中不存在该对象时,我才需要附加该对象。
我浏览了文档,但找不到任何方法。有没有其他方法可以检查这个
ListModel 方法 get(index) 使您能够访问每个元素。它还有一个属性计数,它告诉您其中有多少元素。所以,像这样:
function appendIfNotExist(objectToAppend) { for (var i = 0; i < myListModel.count; i++) { if (myListModel.get(i) == objectToAppend) { return } } ListModel.append(objectToAppend) }