EasyUI Forum
May 20, 2024, 10:09:02 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: show the parent node also  (Read 8205 times)
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« on: January 09, 2014, 02:03:37 PM »

according to this example

http://www.jeasyui.com/tutorial/tree/tree2.php

If I have this structure:

-> Node 1
-> Node 2
--> Node 2.1
--> Node 2.2
--> Node 2.3
-> Node 3
-> Node 4

How I can show only the node 2 and their children?

-> Node 2
--> Node 2.1
--> Node 2.2
--> Node 2.3


Following the demo I just get:

-> Node 2.1
-> Node 2.2
-> Node 2.3

I need to show Parent Node also
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: January 09, 2014, 05:30:59 PM »

Use 'loadFilter' function to customize what data you want.
Code:
<script>
var data = [{
text:'Node 1'
},{
text:'Node 2',
children:[{
text:'Node 2.1'
},{
text:'Node 2.2'
},{
text:'Node 2.3'
}]
},{
text:'Node 3'
},{
text:'Node 4'
}];
</script>
<ul class="easyui-tree" data-options="
data:data,
animate:true,
loadFilter:function(nodes){
return [nodes[1]]; // return the second node
}
"></ul>

Logged
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« Reply #2 on: January 09, 2014, 06:51:01 PM »

hi, stworthy

sorry but is my first tree  Cheesy

if the data were also:

<script>
    var data = [{
               id:100,
       text:'Node 1'
    },{
               id:200,
       text:'Node 2',
       children:[{
                            id:210,
          text:'Node 2.1'
       },{
                            id:220,
          text:'Node 2.2'
       },{
                            id:230,
          text:'Node 2.3'
       }]
    },{
               id:300,
       text:'Node 3'
    },{
               id:400,
       text:'Node 4'
    }];
</script>

then loadfilter:

loadFilter:function(nodes){
 return Huh
}
how can I call for the ID node 200 and their children

thank for your time
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: January 12, 2014, 05:36:55 PM »

Here is the simple implementation to find a node by any property.
Code:
function findBy(data, param, value){
var result = null;
forNodes(data, function(node){
if (node[param] == value){
result = node;
return false;
}
});
return result;
}
function forNodes(data, callback){
var nodes = [];
for(var i=0; i<data.length; i++){
nodes.push(data[i]);
}
while(nodes.length){
var node = nodes.shift();
if (callback(node) == false){return;}
if (node.children){
for(var i=node.children.length-1; i>=0; i--){
nodes.unshift(node.children[i]);
}
}
}
}

Some usage examples:
Code:
var node = findBy(data, 'id', 200);  // find by id
var node = findBy(data, 'text', 'Node 2');  // find by text
Logged
catpaw
Jr. Member
**
Posts: 85


View Profile Email
« Reply #4 on: January 13, 2014, 08:58:11 AM »

very good stworthy

this function will help me a lot

thanks
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!