Browse Source

Pull request #2611: 无JIRA任务 去掉downlist的deepClone和依赖外部的deepClone

Merge in VISUAL/fineui from ~WINDY/fui:master to master

* commit '01050c837b83655733b79c52a84843b4eba26135':
  无JIRA任务 去掉downlist的deepClone和依赖外部的deepClone
es6
windy 3 years ago
parent
commit
acdcad9642
  1. 77
      src/widget/downlist/popup.downlist.js
  2. 66
      src/widget/multilayerdownlist/popup.downlist.js

77
src/widget/downlist/popup.downlist.js

@ -26,8 +26,8 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
this.singleValues = [];
this.childValueMap = {};
this.fatherValueMap = {};
this.items = BI.deepClone(this.options.items);
var self = this, o = this.options, children = this._createChildren(this.items);
this.items = [];
var self = this, o = this.options, children = this._createPopupItems(o.items);
this.popup = BI.createWidget({
type: "bi.button_tree",
items: BI.createItems(children,
@ -75,7 +75,7 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
});
},
_createChildren: function (items) {
_createPopupItems: function (items) {
var self = this, result = [];
// 不能修改populate进来的item的引用
BI.each(items, function (i, it) {
@ -84,8 +84,11 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
items: []
};
BI.each(it, function (i, item) {
if (BI.isNotEmptyArray(item.children) && !BI.isEmpty(item.el)) {
var storeItem = [];
BI.each(it, function (i, sourceItem) {
var item = BI.extend({}, sourceItem);
if (BI.isNotEmptyArray(sourceItem.children) && !BI.isEmpty(sourceItem.el)) {
item.type = "bi.combo_group";
// popup未初始化返回的是options中的value, 在经过buttontree的getValue concat之后,无法区分值来自options
// 还是item自身, 这边控制defaultInit为true来避免这个问题
@ -93,12 +96,13 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
item.cls = "down-list-group";
item.trigger = "hover";
item.isNeedAdjustWidth = false;
item.el.title = item.el.title || item.el.text;
item.el = sourceItem.el;
item.el.title = sourceItem.el.title || sourceItem.el.text;
item.el.type = "bi.down_list_group_item";
item.el.logic = {
dynamic: true
};
item.el.height = item.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
item.el.height = sourceItem.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
item.el.iconCls2 = self.constants.nextIcon;
item.popup = {
lgap: 1,
@ -113,30 +117,10 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
innerVgap: 5,
maxHeight: 378
};
item.el.childValues = [];
item.items = item.children;
BI.each(item.children, function (i, child) {
var fatherValue = BI.deepClone(item.el.value);
var childValue = BI.deepClone(child.value);
self.singleValues.push(child.value);
child.type = child.type || "bi.down_list_item";
child.extraCls = " child-down-list-item";
child.title = child.title || child.text;
child.textRgap = 10;
child.isNeedAdjustWidth = false;
child.logic = {
dynamic: true
};
child.father = fatherValue;
child.childValue = child.value;
self.fatherValueMap[self._createChildValue(fatherValue, childValue)] = fatherValue;
self.childValueMap[self._createChildValue(fatherValue, childValue)] = childValue;
child.value = self._createChildValue(fatherValue, childValue);
item.el.childValues.push(child.value);
});
self._createChildren(item, sourceItem);
} else {
item.type = item.type || "bi.down_list_item";
item.title = item.title || item.text;
item.type = sourceItem.type || "bi.down_list_item";
item.title = sourceItem.title || sourceItem.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
@ -146,6 +130,7 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
var el_done = {};
el_done.el = item;
item_done.items.push(el_done);
storeItem.push(item);
});
if (self._isGroup(item_done.items)) {
BI.each(item_done.items, function (i, item) {
@ -154,6 +139,7 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
}
result.push(item_done);
self.items.push(storeItem);
if (self._needSpliter(i, items.length)) {
var spliter_container = BI.createWidget({
type: "bi.vertical",
@ -176,6 +162,33 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
return result;
},
_createChildren: function (targetItem, sourceItem) {
var self = this;
targetItem.el.childValues = [];
targetItem.items = targetItem.children = [];
BI.each(sourceItem.children, function (i, child) {
var item = BI.extend({}, child);
var fatherValue = BI.deepClone(targetItem.el.value);
var childValue = BI.deepClone(item.value);
self.singleValues.push(item.value);
item.type = item.type || "bi.down_list_item";
item.extraCls = " child-down-list-item";
item.title = item.title || item.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
dynamic: true
};
item.father = fatherValue;
item.childValue = item.value;
self.fatherValueMap[self._createChildValue(fatherValue, childValue)] = fatherValue;
self.childValueMap[self._createChildValue(fatherValue, childValue)] = childValue;
item.value = self._createChildValue(fatherValue, childValue);
targetItem.el.childValues.push(item.value);
targetItem.items.push(item);
});
},
_isGroup: function (i) {
return i.length > 1;
},
@ -239,11 +252,11 @@ BI.DownListPopup = BI.inherit(BI.Pane, {
populate: function (items) {
BI.DownListPopup.superclass.populate.apply(this, arguments);
this.items = BI.deepClone(items);
this.items = [];
this.childValueMap = {};
this.fatherValueMap = {};
this.singleValues = [];
var children = this._createChildren(this.items);
var children = this._createPopupItems(items);
var popupItem = BI.createItems(children,
{}, {
adjustLength: -2

66
src/widget/multilayerdownlist/popup.downlist.js

@ -26,6 +26,7 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
this.singleValues = [];
this.childValueMap = {};
this.fatherValueMap = {};
this.items = [];
var self = this, o = this.options, children = this._createPopupItems(o.items);
this.popup = BI.createWidget({
type: "bi.button_tree",
@ -83,19 +84,22 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
type: "bi.down_list_group",
items: []
};
var storeItem = [];
BI.each(it, function (i, item) {
if (BI.isNotEmptyArray(item.children) && !BI.isEmpty(item.el)) {
BI.each(it, function (i, sourceItem) {
var item = BI.extend({}, sourceItem);
if (BI.isNotEmptyArray(sourceItem.children) && !BI.isEmpty(sourceItem.el)) {
item.type = "bi.combo_group";
item.cls = "down-list-group";
item.trigger = "hover";
item.isNeedAdjustWidth = false;
item.el.title = item.el.title || item.el.text;
item.el = sourceItem.el;
item.el.title = sourceItem.el.title || sourceItem.el.text;
item.el.type = "bi.down_list_group_item";
item.el.logic = {
dynamic: true
};
item.el.height = item.el.height || self.constants.height;
item.el.height = sourceItem.el.height || self.constants.height;
item.el.iconCls2 = self.constants.nextIcon;
item.popup = {
lgap: 1,
@ -110,10 +114,10 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
innerVgap: 5,
maxHeight: 378,
};
self._createChildren(item);
self._createChildren(item, sourceItem);
} else {
item.type = item.type || "bi.down_list_item";
item.title = item.title || item.text;
item.type = sourceItem.type || "bi.down_list_item";
item.title = sourceItem.title || sourceItem.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
@ -123,6 +127,7 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
var el_done = {};
el_done.el = item;
item_done.items.push(el_done);
storeItem.push(item);
});
if (self._isGroup(item_done.items)) {
BI.each(item_done.items, function (i, item) {
@ -131,6 +136,7 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
}
result.push(item_done);
self.items.push(storeItem);
if (self._needSpliter(i, items.length)) {
var spliter_container = BI.createWidget({
type: "bi.vertical",
@ -152,34 +158,35 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
return result;
},
_createChildren: function (item) {
_createChildren: function (targetItem, sourceItem) {
var self = this;
this._formatEL(item).el.childValues = [];
item.items = item.children;
BI.each(item.children, function (i, child) {
child = child.el ? BI.extend(child.el, {children: child.children}) : child;
var fatherValue = BI.deepClone(self._formatEL(item).el.value);
var childValue = BI.deepClone(child.value);
self.singleValues.push(child.value);
child.type = child.type || "bi.down_list_item";
child.extraCls = " child-down-list-item";
child.title = child.title || child.text;
child.textRgap = 10;
child.isNeedAdjustWidth = false;
child.logic = {
this._formatEL(targetItem).el.childValues = [];
targetItem.items = targetItem.children = [];
BI.each(sourceItem.children, function (i, child) {
var item = child.el ? BI.extend({}, child.el, {children: child.children}) : BI.extend({}, child);
var fatherValue = BI.deepClone(self._formatEL(targetItem).el.value);
var childValue = BI.deepClone(item.value);
self.singleValues.push(item.value);
item.type = item.type || "bi.down_list_item";
item.extraCls = " child-down-list-item";
item.title = item.title || item.text;
item.textRgap = 10;
item.isNeedAdjustWidth = false;
item.logic = {
dynamic: true
};
child.father = fatherValue;
item.father = fatherValue;
self.fatherValueMap[self._createChildValue(fatherValue, childValue)] = fatherValue;
self.childValueMap[self._createChildValue(fatherValue, childValue)] = childValue;
child.value = self._createChildValue(fatherValue, childValue);
self._formatEL(item).el.childValues.push(child.value);
item.value = self._createChildValue(fatherValue, childValue);
self._formatEL(targetItem).el.childValues.push(item.value);
if (BI.isNotEmptyArray(child.children)) {
child.type = "bi.down_list_group_item";
child.iconCls2 = self.constants.nextIcon;
child.height = child.height || self.constants.height;
self._createChildren(child);
item.type = "bi.down_list_group_item";
item.iconCls2 = self.constants.nextIcon;
item.height = child.height || self.constants.height;
self._createChildren(item, child);
}
targetItem.items.push(item);
});
},
@ -228,7 +235,7 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
_checkValues: function (values) {
var self = this, o = this.options;
var value = [];
BI.each(o.items, function (idx, itemGroup) {
BI.each(this.items, function (idx, itemGroup) {
BI.each(itemGroup, function (id, item) {
if(BI.isNotNull(item.children)) {
var childValues = getChildrenValue(item);
@ -277,6 +284,7 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
self.childValueMap = {};
self.fatherValueMap = {};
self.singleValues = [];
this.items = [];
var children = self._createPopupItems(items);
var popupItem = BI.createItems(children,
{}, {

Loading…
Cancel
Save