PDA

View Full Version : Tree has to be collapsed to appendChild?!



richiejaeger
10 Apr 2013, 5:22 AM
Hey,

i got the following function to add new childs to an existing node:


saveModule: function(button) {
var win = button.up('window'),
form = win.down('form').getForm(),
tree = this.getController('Format').getFormatSelection(),
store = tree.getStore(),
parent = tree.getSelectionModel().getSelection()[0],
node = store.getNodeById(parent.getId());


if (form.isValid()) {
//tree.collapseAll();

var record = node.createNode({ name: form.findField('module_id').getStore().findRecord('id', form.getFieldValues().module_id).get('name'), leaf: true, parentId: parent.getId() });
node.appendChild(record);
record.save({
success: function() {
win.close();
store.reload();
}
});
}
}

The node gets created via my proxy. I can also find the new record in my Database. But i get an error, if i add the childnode to an expanded node:


Uncaught TypeError: Cannot read property 'internalId' of undefined

If i add an record to an collapsed node, i dont get any error...

Is this problem known or am i just doing something wrong?!

Regards
Richie

slemmon
11 Apr 2013, 5:23 PM
This works for me in 4.2:
You want to see if it fails when you try with it?



var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true },
{ text: "algebra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});


Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 220,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
, tbar: [{
text: 'Add node'
, handler: function (btn) {
var dest = btn.up('treepanel').getRootNode().getChildAt(1);
dest.appendChild({text: 'added', leaf: true});
}
}]
});