在图的第一负载我添加在我的模型三个要素:为什么在GoJS diagram.model.nodeDataArray的长度从diagram.findNodesByExample的结果不同({})
var model = new go.GraphLinksModel();
model.nodeKeyProperty = 'goKey';
model.nodeCategoryProperty = 'goType';
model.addNodeDataCollection([
{
goKey: 'instance1',
goType: 'component',
//other data
}, {
goKey: 'instance2',
goType: 'tcp',
//other data
}, {
goKey: 'instance3',
goType: 'tcp',
//other data
}]);
diagram.model = model;
console.log(diagram.findNodesByExample({}).count); //3
console.log(diagram.model.nodeDataArray.length); //3
然后我除去两个项目与goType:“TCP”使用diagram.model.removeNodeData方法和模型中再次添加它们:
var item2 = _.find(diagram.model.nodeDataArray, {goKey: 'instance2'});
var item3 = _.find(diagram.model.nodeDataArray, {goKey: 'instance3'});
model.removeNodeData(item2);
model.removeNodeData(item3);
console.log(diagram.model.nodeDataArray.length); //1
console.log(diagram.findNodesByExample({}).count); //1
diagram.model.addNodeDataCollection([{
goKey: 'instance2',
goType: 'tcp',
//other data
}, {
goKey: 'instance3',
goType: 'tcp',
//other data
}]);
但毕竟这在图不同节点的数量,我只看到两个在画布上的节点:
console.log(diagram.model.nodeDataArray.length); //3
console.log(diagram.findNodesByExample({}).count); //2
如果看一看diagram.findNodesByExample({}),使用方法每个,我看到INSTANCE2才被加入的结果:
diagram.findNodesByExample({}).each(function (item) {
console.log(item.data.goKey);
});
// instance1
// instance2
我做错了什么?
谢谢你的回答,但问题是重复使用已删除的节点。删除** __ gohashid **后,它已被修复。 – blackhard