EasyUI Forum

General Category => General Discussion => Topic started by: catpaw on March 09, 2017, 06:57:50 PM



Title: append and loadFilter (tree)
Post by: catpaw on March 09, 2017, 06:57:50 PM
hello

Im using tree with loadFilter:

Code:
<ul id="t" class="easyui-tree" data-options="
                        url:'../retrieve/get.php',
                        method:'get',
                        animate:true,
                        lines:true,
                        loadFilter:treeFilter"></ul>

function treeFilter(rows,parent){
for(var i=0; i<rows.length; i++){
rows[i]['text'] = rows[i]['name'];
}
var nodes = [];
// get the top level nodes
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (!row._parentId){
nodes.push(row);
rows.splice(i,1);
i--;
}
}
var toDo = [];
for(var i=0; i<nodes.length; i++){
toDo.push(nodes[i]);
}
while(toDo.length){
var node = toDo.shift(); // the parent node
// get the children nodes
for(var i=0; i<rows.length; i++){
var row = rows[i];
if (row._parentId == node.id){
if (node.children){
node.children.push(row);
} else {
node.children = [row];
}
toDo.push(row);
rows.splice(i,1);
i--;
}
}
}
return nodes;
}

the data shows properly, but when I try to append a child node, the node always apear in the same level of root:

Code:
var node = $('#t').tree('getSelected');
$('#t').tree('append', {
_parentId: node.id,
data: [{
id: 11,
name: 'new_name'
}]
});

I think " _parentId " is not been recognized and the node always take no parent as the root node

example:

-- root (id:1)
---- folder (id:2) <--------- append node "new"
------- file (id:3)

should be:

-- root (id:1)
---- folder (id:2)
------- file (id:3)
------- new (id:4)
 
instead I get:

-- root (id:1)
---- folder (id:2)
------- file (id:3)
-- new (id:4)

What Im trying to said is that "new" should by child of "folder" not on the same level of "root"

In the data base is saved properly and when I reload the tree "new" is in the right place

But I dont want/can reload the tree for this particulary case

some idea?

thanks


Title: Re: append and loadFilter (tree)
Post by: stworthy on March 10, 2017, 06:40:42 PM
When appending a new node to the tree, you should set the 'parent' property to indicate the parent node. Please use this code instead.
Code:
var node = $('#tt').tree('getSelected');
$('#tt').tree('append', {
parent: node.target,
data: [{
id: 11,
name: 'new_name'
}]
});


Title: Re: append and loadFilter (tree)
Post by: catpaw on March 12, 2017, 01:50:19 PM
that is correct, thank you

I was trying with node.id instead node.target and was getting error

now is properly