I am trying to dynamically add new nodes using following code:
var root = this.treeStore.getRootNode();
var n = {
id:--this.counter,
leaf: (type=='group') ? false : true,
expanded:true,
cls:'redtext',
text: (name == undefined) ? 'Nowa warstwa': name,
gsip:{
isGroup: (type=='group') ? true : false,
layer:{}
}
};
root.appendChild(n);
The above code adds new node to root node but, what is strange, the newly created node cotains all the children of the root node. So the tree crashes as there are nodes with same id. When i remove id:--this.counter
, everything works fine. I need this id and the one i provide is unique. The newly created node has internalId different than id, all other existing nodes have internalId=data.id.
Below store and model code:
Ext.define('GSIP_PORTAL.model.Layer',{
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'} , 'text', 'leaf', 'gsip'],
idProperty:'id'
});
Ext.define('GSIP_PORTAL.store.Layers', {
extend: 'Ext.data.TreeStore',
model:'GSIP_PORTAL.model.Layer',
proxy: {
type: 'ajax',
url: dispatcher.getUrl('getProfile'),
reader: {
type: 'json',
root: 'layers'
}
},
defaultRootId:0,
root:{
expanded:true
}
});
Below is json response used to build tree. I use this json to build tree at once that is why i have attribute layers as root.
{
"id":10003,
"name":"GSIP",
"defaultProfile":false,
"layers":[
{
"id":10012,
"expanded":true,
"text":"GSIP",
"leaf":false,
"layers":[
{
"id":10013,
"expanded":true,
"text":"Dzialki",
"leaf":true,
"layers":[
],
"gsip":{
"displayName":"Dzialki",
"internalName":"test",
"isGroup":false,
"layer":{
"id":1006,
"type":{
"id":1002,
"name":"WMS (queryable)",
"description":"WMS z zapytaniami GetFeatureInfo."
},
"url":"http://192.168.21.10:8080/geoserver/gsip/wms",
"layerName":"egb_dzialki"
},
"order":0
}
}
],
"gsip":{
"displayName":"GSIP",
"internalName":"test",
"isGroup":true,
"order":0
}
}
],
"tools":[
]
}
I get following ext-all-debug error after adding new node TypeError: records[i] is undefined
in line:
ns[i].viewRecordId = records[i].internalId
;
--this.counter
is unique, even when compared with ids returned from the server (like that of root)? – Izhaki