diff --git a/bi/widget.js b/bi/widget.js index 0863124f0..2bc53e8ab 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -17265,7 +17265,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return; } BI.each(selected, function (k) { - var node = self._getNode(parentValues, k); + var node = self._getTreeNode(parentValues, k); var newParents = BI.clone(parentValues); newParents.push(node.value); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); @@ -17312,37 +17312,33 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree function dealWithSelectedValues(selectedValues) { + var p = parentValues.concat(notSelectedValue); //存储的值中存在这个值就把它删掉 - if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + if (canFindKey(selectedValues, p)) { //如果搜索的值在父亲链中 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { - var name = notSelectedValue; - var p = parentValues; - var pNode = getNode(selectedValues, parentValues); - if (pNode[name]) { - delete pNode[name]; - //递归删掉空父节点 - while (p.length > 0 && BI.isEmpty(pNode)) { - name = p[p.length - 1]; - p = p.slice(0, p.length - 1); - pNode = getNode(selectedValues, p); - delete pNode[name]; - } + if (isSearchValueInParent(p)) { + self._deleteNode(selectedValues, p); + } else { + var searched = []; + var finded = search(parentValues, notSelectedValue, [], searched); + if (finded && BI.isNotEmptyArray(searched)) { + BI.each(searched, function (i, arr) { + self._deleteNode(selectedValues, arr); + }) } } } //存储的值中不存在这个值,但父亲节点是全选的情况 - if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + if (isChild(selectedValues, p)) { var result = [], finded = false; - var p = parentValues; //如果parentValues中有匹配的值,说明搜索结果不在当前值下 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + if (isSearchValueInParent(p)) { finded = true; - p = parentValues.concat(notSelectedValue); } else { //从当前值开始搜 finded = search(parentValues, notSelectedValue, result); + p = parentValues; } if (finded === true) { @@ -17379,10 +17375,11 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } - function search(parents, current, result) { + function search(parents, current, result, searched) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { + searched && searched.push(newParents); return true; } @@ -17392,7 +17389,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var can = false; BI.each(children, function (i, child) { - if (search(newParents, child.value, result)) { + if (search(newParents, child.value, result, searched)) { can = true; } else { notSearch.push(child.value); @@ -17417,17 +17414,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return false; } - function getNode(selectedValues, parentValues) { - var pNode = selectedValues; - for (var i = 0, len = parentValues.length; i < len; i++) { - if (pNode == null) { - return null; - } - pNode = pNode[parentValues[i]]; - } - return pNode; - } - function canFindKey(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -17576,7 +17562,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { - var node = self._getNode(parentValues, value) + var node = self._getTreeNode(parentValues, value) result.push({ id: node.id, pId: node.pId, @@ -17738,6 +17724,32 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } }, + _getNode: function (selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + }, + + _deleteNode: function (selectedValues, values) { + var name = values[values.length - 1]; + var p = values.slice(0, values.length - 1); + var pNode = this._getNode(selectedValues, p); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = this._getNode(selectedValues, p); + delete pNode[name]; + } + } + }, _buildTree: function (jo, values) { var t = jo; @@ -17754,7 +17766,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return finded.finded.length > 0 || finded.matched.length > 0; }, - _getNode: function (parentValues, v) { + _getTreeNode: function (parentValues, v) { var self = this; var findedParentNode; var index = 0; @@ -17781,7 +17793,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree _getChildren: function (parentValues) { if (parentValues.length > 0) { var value = BI.last(parentValues); - var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value); + var parent = this._getTreeNode(parentValues.slice(0, parentValues.length - 1), value); } else { var parent = this.tree.getRoot(); } diff --git a/docs/widget.js b/docs/widget.js index 0863124f0..2bc53e8ab 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -17265,7 +17265,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return; } BI.each(selected, function (k) { - var node = self._getNode(parentValues, k); + var node = self._getTreeNode(parentValues, k); var newParents = BI.clone(parentValues); newParents.push(node.value); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); @@ -17312,37 +17312,33 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree function dealWithSelectedValues(selectedValues) { + var p = parentValues.concat(notSelectedValue); //存储的值中存在这个值就把它删掉 - if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + if (canFindKey(selectedValues, p)) { //如果搜索的值在父亲链中 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { - var name = notSelectedValue; - var p = parentValues; - var pNode = getNode(selectedValues, parentValues); - if (pNode[name]) { - delete pNode[name]; - //递归删掉空父节点 - while (p.length > 0 && BI.isEmpty(pNode)) { - name = p[p.length - 1]; - p = p.slice(0, p.length - 1); - pNode = getNode(selectedValues, p); - delete pNode[name]; - } + if (isSearchValueInParent(p)) { + self._deleteNode(selectedValues, p); + } else { + var searched = []; + var finded = search(parentValues, notSelectedValue, [], searched); + if (finded && BI.isNotEmptyArray(searched)) { + BI.each(searched, function (i, arr) { + self._deleteNode(selectedValues, arr); + }) } } } //存储的值中不存在这个值,但父亲节点是全选的情况 - if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + if (isChild(selectedValues, p)) { var result = [], finded = false; - var p = parentValues; //如果parentValues中有匹配的值,说明搜索结果不在当前值下 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + if (isSearchValueInParent(p)) { finded = true; - p = parentValues.concat(notSelectedValue); } else { //从当前值开始搜 finded = search(parentValues, notSelectedValue, result); + p = parentValues; } if (finded === true) { @@ -17379,10 +17375,11 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } - function search(parents, current, result) { + function search(parents, current, result, searched) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { + searched && searched.push(newParents); return true; } @@ -17392,7 +17389,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree var can = false; BI.each(children, function (i, child) { - if (search(newParents, child.value, result)) { + if (search(newParents, child.value, result, searched)) { can = true; } else { notSearch.push(child.value); @@ -17417,17 +17414,6 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return false; } - function getNode(selectedValues, parentValues) { - var pNode = selectedValues; - for (var i = 0, len = parentValues.length; i < len; i++) { - if (pNode == null) { - return null; - } - pNode = pNode[parentValues[i]]; - } - return pNode; - } - function canFindKey(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -17576,7 +17562,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { - var node = self._getNode(parentValues, value) + var node = self._getTreeNode(parentValues, value) result.push({ id: node.id, pId: node.pId, @@ -17738,6 +17724,32 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree } }, + _getNode: function (selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + }, + + _deleteNode: function (selectedValues, values) { + var name = values[values.length - 1]; + var p = values.slice(0, values.length - 1); + var pNode = this._getNode(selectedValues, p); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = this._getNode(selectedValues, p); + delete pNode[name]; + } + } + }, _buildTree: function (jo, values) { var t = jo; @@ -17754,7 +17766,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree return finded.finded.length > 0 || finded.matched.length > 0; }, - _getNode: function (parentValues, v) { + _getTreeNode: function (parentValues, v) { var self = this; var findedParentNode; var index = 0; @@ -17781,7 +17793,7 @@ BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane);BI.AbstractTree _getChildren: function (parentValues) { if (parentValues.length > 0) { var value = BI.last(parentValues); - var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value); + var parent = this._getTreeNode(parentValues.slice(0, parentValues.length - 1), value); } else { var parent = this.tree.getRoot(); } diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index 40c6acfc9..e32b1fdd1 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -77,7 +77,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { return; } BI.each(selected, function (k) { - var node = self._getNode(parentValues, k); + var node = self._getTreeNode(parentValues, k); var newParents = BI.clone(parentValues); newParents.push(node.value); createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); @@ -124,37 +124,33 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { function dealWithSelectedValues(selectedValues) { + var p = parentValues.concat(notSelectedValue); //存储的值中存在这个值就把它删掉 - if (canFindKey(selectedValues, parentValues.concat(notSelectedValue))) { + if (canFindKey(selectedValues, p)) { //如果搜索的值在父亲链中 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { - var name = notSelectedValue; - var p = parentValues; - var pNode = getNode(selectedValues, parentValues); - if (pNode[name]) { - delete pNode[name]; - //递归删掉空父节点 - while (p.length > 0 && BI.isEmpty(pNode)) { - name = p[p.length - 1]; - p = p.slice(0, p.length - 1); - pNode = getNode(selectedValues, p); - delete pNode[name]; - } + if (isSearchValueInParent(p)) { + self._deleteNode(selectedValues, p); + } else { + var searched = []; + var finded = search(parentValues, notSelectedValue, [], searched); + if (finded && BI.isNotEmptyArray(searched)) { + BI.each(searched, function (i, arr) { + self._deleteNode(selectedValues, arr); + }) } } } //存储的值中不存在这个值,但父亲节点是全选的情况 - if (isChild(selectedValues, parentValues.concat(notSelectedValue))) { + if (isChild(selectedValues, p)) { var result = [], finded = false; - var p = parentValues; //如果parentValues中有匹配的值,说明搜索结果不在当前值下 - if (isSearchValueInParent(parentValues.concat(notSelectedValue))) { + if (isSearchValueInParent(p)) { finded = true; - p = parentValues.concat(notSelectedValue); } else { //从当前值开始搜 finded = search(parentValues, notSelectedValue, result); + p = parentValues; } if (finded === true) { @@ -191,10 +187,11 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } - function search(parents, current, result) { + function search(parents, current, result, searched) { var newParents = BI.clone(parents); newParents.push(current); if (self._isMatch(current, keyword)) { + searched && searched.push(newParents); return true; } @@ -204,7 +201,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { var can = false; BI.each(children, function (i, child) { - if (search(newParents, child.value, result)) { + if (search(newParents, child.value, result, searched)) { can = true; } else { notSearch.push(child.value); @@ -229,17 +226,6 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { return false; } - function getNode(selectedValues, parentValues) { - var pNode = selectedValues; - for (var i = 0, len = parentValues.length; i < len; i++) { - if (pNode == null) { - return null; - } - pNode = pNode[parentValues[i]]; - } - return pNode; - } - function canFindKey(selectedValues, parents) { var t = selectedValues; for (var i = 0; i < parents.length; i++) { @@ -388,7 +374,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { - var node = self._getNode(parentValues, value) + var node = self._getTreeNode(parentValues, value) result.push({ id: node.id, pId: node.pId, @@ -550,6 +536,32 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } }, + _getNode: function (selectedValues, parentValues) { + var pNode = selectedValues; + for (var i = 0, len = parentValues.length; i < len; i++) { + if (pNode == null) { + return null; + } + pNode = pNode[parentValues[i]]; + } + return pNode; + }, + + _deleteNode: function (selectedValues, values) { + var name = values[values.length - 1]; + var p = values.slice(0, values.length - 1); + var pNode = this._getNode(selectedValues, p); + if (pNode[name]) { + delete pNode[name]; + //递归删掉空父节点 + while (p.length > 0 && BI.isEmpty(pNode)) { + name = p[p.length - 1]; + p = p.slice(0, p.length - 1); + pNode = this._getNode(selectedValues, p); + delete pNode[name]; + } + } + }, _buildTree: function (jo, values) { var t = jo; @@ -566,7 +578,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { return finded.finded.length > 0 || finded.matched.length > 0; }, - _getNode: function (parentValues, v) { + _getTreeNode: function (parentValues, v) { var self = this; var findedParentNode; var index = 0; @@ -593,7 +605,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { _getChildren: function (parentValues) { if (parentValues.length > 0) { var value = BI.last(parentValues); - var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value); + var parent = this._getTreeNode(parentValues.slice(0, parentValues.length - 1), value); } else { var parent = this.tree.getRoot(); }