将对象附加到 ListModel 时,一个键显示 2 次。
这是我的代码:
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
visible: true
width: 640
height: 480
ListModel {
id: modelCategory
Component.onCompleted: {
var cr = [{"nid":[{"value":"17"}],"uuid":[{"value":"f68wb2f2-11a0-457b-b8f4-a3bf55bea3d5"}],"vid":[{"value":"17"}],"langcode":[{"value":"en"}],"type":[{"target_id":"category","target_type":"node_type","target_uuid":"12d62f50-2d60-4c9f-96fb-0351df3e4223"}],"title":[{"value":"Restaurant "}],"uid":[{"target_id":"2","target_type":"user","target_uuid":"0a4c1442-f9b5-4cdb-96d3-f3a6bb35d5dd","url":"\/user\/2"}],"status":[{"value":"1"}],"created":[{"value":"1477296867"}],"changed":[{"value":"1477297787"}]}]
populateCategory(cr);
console.log(JSON.stringify(modelCategory.get(0)))
}
}
function populateCategory(categoryResult) {
modelCategory.clear()
for (var i in categoryResult) {
var obj = {
_id: categoryResult[i].nid[0].value,
categoryName: categoryResult[i].title[0].value
}
modelCategory.append(obj)
}
}
}
我populateCategory()
从一个附加对象的 JavaScript 文件中调用。打印其中一个模型项目时,我得到:
{"categoryName":"Restaurant","_id":"17","_id":"17"}
它给出了两个_ids
. 这是为什么?它破坏了QSortFilterProxyModel的过滤,甚至没有在任何视图中显示。
有什么建议么?