EasyUI Forum
March 29, 2024, 06:17:07 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: append and loadFilter (tree)  (Read 8417 times)
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« 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
« Last Edit: March 09, 2017, 08:27:21 PM by catpaw » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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'
}]
});
Logged
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« Reply #2 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!