1 <div class="apiDetail">
\r
3 <h2><span>Function(filter, isSingle, parentNode, invokeParam)</span><span class="path">zTreeObj.</span>getNodesByFilter</h2>
\r
4 <h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jquery.ztree.core</span> js ]</span></h3>
\r
7 <div class="longdesc">
\r
8 <p>Search the single node's data or collection of nodes's data by custom rules.</p>
\r
9 <p class="highlight_red">Can be customized complex search rules.</p>
\r
10 <p class="highlight_red">Please use zTree object to executing the method.</p>
\r
13 <h3>Function Parameter Descriptions</h3>
\r
15 <h4><b>filter</b><span>Function</span></h4>
\r
16 <p>Custom search function. e.g. function filter(node) {...}</p>
\r
17 <p>filter's parameter: node (node's data -- JSON)</p>
\r
18 <p>filter's return: boolean (true means: match the rules; false means: don't match the rules)</p>
\r
19 <h4 class="topLine"><b>isSingle</b><span>Boolean</span></h4>
\r
20 <p>isSingle = true means: search only one node</p>
\r
21 <p>isSingle = false means: search the array of the nodes</p>
\r
22 <p class="highlight_red">If this parameter is omitted, as same as false</p>
\r
23 <h4 class="topLine"><b>parentNode</b><span>JSON</span></h4>
\r
24 <p>The search range, you can search node from a parent node's child nodes.</p>
\r
25 <p class="highlight_red">If this parameter is omitted, zTree will search node from all nodes.</p>
\r
26 <h4 class="topLine"><b>invokeParam</b><span>anything</span></h4>
\r
27 <p>Custom data object by user, used to calculate in the filter function.</p>
\r
28 <h4 class="topLine"><b>Return </b><span>Array(JSON) / JSON</span></h4>
\r
29 <p>If isSingle = true, will return the first node's data (JSON) what be matched. If no match, return null.</p>
\r
30 <p>If isSingle = false, will return the array of all nodes's data what be matched. if no match, return [ ].</p>
\r
32 <h3>Examples of function</h3>
\r
33 <h4>1. Search the nodes which their 'name' contains 'test' and 'level' is 2.</h4>
\r
34 <pre xmlns=""><code>function filter(node) {
\r
35 return (node.level == 2 && node.name.indexOf("test")>-1);
\r
38 var treeObj = $.fn.zTree.getZTreeObj("tree");
\r
39 var node = treeObj.getNodesByFilter(filter, true); // search only one node
\r
40 var nodes = treeObj.getNodesByFilter(filter); // search the array of the nodes
\r