PDA

View Full Version : Creating Treenode after AJAX request



thaberkern
31 Jul 2007, 6:16 AM
Hello all,

i'm pretty new to ext, so forgive me if i ask stupid questions...

I hav some problems with the tree component. What i'm trying to do.
I have a context menu for groups (AsyncTreeNodes) and added a "new group" command. In the handler of this command i aks the user for a name (Ext.MessageBox.prompt), afterwards i'm calling aphp script that returns me all data of the new group in the database (i.w. id). The result is returned as JSON.

This is what i do



function onAddGroup() {
var node = tree.getSelectionModel().getSelectedNode();

Ext.MessageBox.prompt('easymaterial', 'Bitte geben Sie einen Gruppennamen ein:', function(btn, text){
if (btn == 'ok'){
new Ajax.Request('<?php echo url_for('/Group/add');?>',
{
method:'get',
parameters: {pnid: node.id, name: text},
onSuccess: function(transport, json){
alert(json.text);
alert(json.id);
alert(json.allowDelete);
alert(json.cls);
alert(json.nodeType);

var new_node = new Tree.TreeNode({
text: json.text,
id: json.id,
allowDelete: json.allowDelete,
cls: json.cls,
nodeType: json.nodeType
});

alert (new_node);
node.appendChild(new_node);

tree.render();
},
onFailure: function(){ alert('Something went wrong...') }
});
}
else
{
return;
}
});
}


The problem is that the alert (new_node) is never called :-/

I tried a lot of thing, but nothing worked :((

Please help

Timo

31 Jul 2007, 3:21 PM
There is an example on how to do trees via XHR in the docs.

thaberkern
31 Jul 2007, 9:19 PM
Yes i know. And i have no problems get an Async Treenode loading all its subnodes. But my questions is how to add a single node after a XHR as you can see in my posted code

Timo