Insert Node inside another Node
Escrito el 9 de January del 2009 por wktd.If I have this tree:
root (AsyncTreeNode)
-Category1 (id: cat1)
---Node1
---Node2
-Category2 (id: cat2)
---Node3
---Node4
And if I go to "Add Node" Button, I wish to add a new Node inside "Category2". How can i do that?
I have this code, but this code insert the new Node inside root node:
this.root.appendChild(node);
Here is the code:
var getfeeds = new Ext.tree.TreeLoader({
dataUrl: 'script.php',
baseParams:{
accion: 'listar'
}
});
var root = new Ext.tree.AsyncTreeNode({
text: 'Feeds',
id:'feeds',
expanded: true,
allowDrag:false,
allowDrop:false
});
var tree = new Ext.tree.TreePanel({
id:'feed-tree',
region:'west',
title:'Listado Feeds',
split:true,
width: 210,
minSize: 210,
maxSize: 400,
collapsible: true,
animate:true,
maskDisabled: false,
margins:'0 0 0 0',
cmargins:'0 5 0 5',
rootVisible:true,
enableDD:true,
root: root,
loader: getfeeds,
lines:false,
autoScroll:true,
collapseFirst:false,
tbar: [{
iconCls:'add-feed',
text:'Agregar Feed',
handler: this.showWindow,
scope: this
},{
id:'delete',
iconCls:'delete-icon',
text:'Borrar Feed',
handler: function(){
var s = this.getSelectionModel().getSelectedNode();
if(s){
this.removeFeed(s.attributes.id);
}
},
scope: this
}],
bbar: [{
iconCls:'add-feed-cat',
text:'Agregar Categoría',
scope: this
}, '->',{
iconCls:'refresh3',
text:'Actualizar',
handler: function(){
root.reload();
},
scope: this
}]
});
And script.php have:
function listar(){
global $tablaCat;
$sql = "SELECT * FROM ".$tablaCat;
$result = mysql_query($sql);
while($recCat = mysql_fetch_array($result, MYSQL_ASSOC)){
$children = getFeeds($recCat['id']);
if($children){
$tmp['id'] = 'cat-'.$recCat['id'];
$tmp['text'] = htmlentities($recCat['nombre']);
$tmp['leaf'] = false;
$tmp['cls'] = 'feeds-node';
$tmp['iconCls'] = 'add-feed-cat';
$tmp['children'] = $children;
}else{
$tmp['id'] = 'cat-'.$recCat['id'];
$tmp['text'] = htmlentities($recCat['nombre']);
$tmp['leaf'] = true;
$tmp['cls'] = 'feeds-node';
$tmp['iconCls'] = 'add-feed-cat';
}
$nodes = $tmp;
}
if (version_compare(PHP_VERSION,"5.2","<")){
require_once("../../extjs/php/JSON.php");
$json = new Services_JSON();
$data=$json->encode($nodes);
}else{
$data = json_encode($nodes);
}
echo $data;
}
function getFeeds($id){
global $tabla;
$sql = "SELECT * FROM ".$tabla." WHERE id_cat = '".$id."'";
$result = mysql_query($sql);
while($rec = mysql_fetch_array($result, MYSQL_ASSOC)){
$tmp['id'] = 'hijo-'.$rec['id'];
$tmp['text'] = htmlentities($rec['text']);
$tmp['url'] = $rec['url'];
$tmp['leaf'] = true;
$tmp['cls'] = 'feed';
$tmp['iconCls'] = 'feed-icon';
$nodes = $tmp;
}
return $nodes;
}
I can insert inside the root node, but in other node, give me an error.
I tried with this:
this.asd = Ext.getCmp('feed-tree').getRootNode().getNodeById('cat1').appendChi ld(
new Ext.tree.TreeNode({
text:'ASD',
id:'asd',
cls:'feeds-node',
expanded:true
})
);
Firebug returns:
Ext.getCmp("feed-tree").getRootNode().getNodeById is not a function
var node = tree.getNodeById('cat1');
node.appendChild(newNode);
I have this tree:
-root (AsyncTreeNode)
---Node1(id: cat1)
-----Node2
-----Node3
---Node4 (id: cat2)
-----Node5
-----Node6
This is what i do:
this.root.appendChild(node);
..returns
-root (AsyncTreeNode)
---Node1(id: cat1)
-----Node2
-----Node3
---Node4 (id: cat2)
-----Node5
-----Node6
---NEW NODE
This is what i want:
-root (AsyncTreeNode)
---Node1(id: cat1)
-----Node2
-----Node3
-----NEW NODE
---Node4 (id: cat2)
-----Node5
-----Node6
#If you have any other info about this subject , Please add it free.# |
Catalogado bajo homelessguestb.comedit
