From acdb78622ec36e332e5aec5331c3162fb810fefa Mon Sep 17 00:00:00 2001 From: "jnhuang@telenavsoftware.com" Date: Wed, 24 Jul 2019 17:44:53 +0800 Subject: [PATCH] Make the filterFunc in expand works recursively --- libs/jsonTree/jsonTree.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/jsonTree/jsonTree.js b/libs/jsonTree/jsonTree.js index 51bbf01..487546f 100644 --- a/libs/jsonTree/jsonTree.js +++ b/libs/jsonTree/jsonTree.js @@ -543,8 +543,9 @@ var jsonTree = (function() { * Expands this list of node child nodes * * @param isRecursive {boolean} - if true, expands all child nodes + * @param {Function} filterFunc - 'true' if this node should be expanded */ - expand : function(isRecursive){ + expand : function(isRecursive, filterFunc){ if (this.isEmpty) { return; } @@ -556,7 +557,14 @@ var jsonTree = (function() { if (isRecursive) { this.childNodes.forEach(function(item, i) { if (item.isComplex) { - item.expand(isRecursive); + if (typeof filterFunc == 'function'){ + if(filterFunc(item)){ + item.expand(isRecursive, filterFunc); + } + } else { + item.expand(isRecursive); + } + } }); } @@ -745,7 +753,7 @@ var jsonTree = (function() { if (typeof filterFunc == 'function') { this.rootNode.childNodes.forEach(function(item, i) { if (item.isComplex && filterFunc(item)) { - item.expand(); + item.expand('recursive', filterFunc); } }); } else {