Is it possible to get a node by its internalId? I tried:
Store
Ext.define('myStore', {
extend: 'Ext.data.TreeStore',
storeId: 'treestore',
root: {
text: 'root',
children: [{
text: 'leaf1',
id: 'leaf1',
children: [{
text: 'child1',
id: 'child1',
leaf: true
},{
text: 'child2',
id: 'child2',
leaf: true
}]
},{
text: 'leaf2',
id: 'leaf2',
leaf: true
},{
text: 'leaf3',
id: 'leaf3',
leaf: true
}]
},
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});
Tree
Ext.create('Ext.tree.Panel', {
id: 'myTree',
rootVisible: false,
store: Ext.create('myStore'),
width: 300,
height: 500,
renderTo: Ext.getBody()
});
Adding and getting node
Ext.getCmp('myTree').getRootNode().appendChild({id: 'test', text: 'test', leaf: true}); // this test node takes on the internalId 'ext-record-2'
Ext.getCmp('myTree').store.getNodeById('ext-record-2'); // returns undefined
Ext.getCmp('myTree').getRootNode().findChild('id', 'ext-record-2', true); // returns null
Ext.getCmp('myTree').getRootNode().findChild('internalId', 'ext-record-2', true); // I was just trying things at this point.
I realize this probably isn’t possible, so I’ll explain what I’m trying to do… I’m trying to change the id of a node, so when I use getNodeById, I can use the new id that I made. The idea is, if I changed the id, I could find it in the tree and it would be unique because I only allow for adding unique id’s… but the id wouldn’t change. I then thought using the ‘ext-record’ id would make sure I return a unique id, but then I couldn’t figure that out, haha.
Here’s some code showing what I’d like to do.
var node = Ext.getCmp('myTree').store.getNodeById('test'); // returns my test node
node.beginEdit();
node.set('id', 'blah');
node.endEdit();
node.commit(false);
alert(Ext.getCmp('myTree').store.getNodeById('blah')); // returns undefined
alert(Ext.getCmp('myTree').store.getNodeById('test')); // still returns my test node
I tried using the tree’s sync method, but that didn’t do anything. I’m just wondering how I can update the node’s id, so when I use getNodeById, I can use the new id. Any thoughts?
Couple things:
Try to debug it step by step. I.e. debug what you’re getting after Ext.getCmp().store and Ext.getCmp().getTreeRoot(). Check if the node has any children in array.
What exactly is beginEdit/endEdit? NodeInterface doesn’t have these methods.
Why are you trying to change Id? I’m just curious – it’s very unusual task for my taste.