Reputation: 1983
I have a typical problem here like, I am trying to replicate the folder structure on the server using the TreePanel. The scenario is that I have some folders which are having repeated children. that is, the file/folder name is same which is the Node id
. When I try to expand and collapse the parent is unable to map to 2 children and the expand is creating duplicate folders.
Code before appending node is , I have extended the Tree like,
Ext.define("my.widget.ContentTree",
{
extend: "Ext.tree.Panel",
alias: "widget.my_content_tree",
...
// beforeappend event required for node initialization
this.store.on("beforeappend", onBeforeAppendNode, this);
this.store.on("append", onAppendNode, this);
And this line of code is the logic before appending node.
function onBeforeAppendNode(parent, newNode) {
/* ext js expands & collapses the tree w.r.t internalId. This Id is by
default set to the node ID. Appending the parent id to the child with
additonal timestamp ensures that there cannot be duplicate IDS
No adverse effects if the internal ids are changed. its neither persisted
nor any state is maintained w.r.t to internal ID.*/
// Important Line Start
if(parent!=null)
newNode.internalId=newNode.internalId+"_"+parent.get("id")+"_"+Math.round(new
Date().getTime()) ;
// Important Line End
var nid = newNode.get("id");
...
My Logic is that I change the internalID of the tree by appending it with the parent id & timestamp.
My question is , If my approach is correct? because I am trying to find an EXT js API which does this but I couldnt find a one.
Can anyone please help.
Thank you.
Upvotes: 2
Views: 2495
Reputation: 15673
I ran into the same issue. The tree does not support two records with identical IDs.
If you do not have editable tree panel, than you might not care about IDs and so should not include it into your model class. Remember that idProperty default to ID field. If you dont bring it in from the server it will be OK.
Alternatively you can have server fake unique IDs but if you ever send your data back to the server you will need to handle that.
Upvotes: 1