Browse Source

Pull request #3098: KERNEL-12250 feat:简化一下combolist的api

Merge in VISUAL/fineui from ~TREECAT/fineui:master to master

* commit '8efb8ba0e84da26b555e832243fdc40a7b7c6708':
  KERNEL-12250 feat:简化一下combolist的api
es6
treecat-罗群 2 years ago
parent
commit
3cf6e2640c
  1. 6
      demo/js/widget/downlist/demo.downlist.js
  2. 31
      src/widget/downlist/combo.downlist.js

6
demo/js/widget/downlist/demo.downlist.js

@ -47,11 +47,9 @@ Demo.Downlist = BI.inherit(BI.Widget, {
width: 100, width: 100,
items: [ items: [
[{ [{
el: {
text: "column 1111", text: "column 1111",
iconCls1: "dot-e-font", iconCls1: "dot-e-font",
value: 12 value: 12,
},
children: [{ children: [{
text: "column 1.1", text: "column 1.1",
value: 21, value: 21,
@ -166,13 +164,11 @@ Demo.Downlist = BI.inherit(BI.Widget, {
}], }],
items: [ items: [
[{ [{
el: {
text: "选项一", text: "选项一",
value: 1, value: 1,
icon: { icon: {
type: "demo.downlist.icon", type: "demo.downlist.icon",
}, },
},
children: [{ children: [{
text: "选项一", text: "选项一",
value: 11, value: 11,

31
src/widget/downlist/combo.downlist.js

@ -1,3 +1,31 @@
(function() {
function transformItems(items) {
if (!items) return items;
var result = BI.cloneDeep(items);
var isComplexItmes = BI.some(items, function (_, item) {
return BI.isArray(item);
});
// 传一维数组,帮转二维
if (!isComplexItmes) {
result = [result];
}
// 帮转 el
BI.each(result, function (_, arr) {
BI.each(arr, function (_, item) {
if (item.children && !item.el) {
item.el = {
text: item.text,
icon: item.icon,
cls: item.cls,
iconCls1: item.iconCls1,
value: item.value
};
}
});
});
return result;
}
/** /**
* Created by roy on 15/8/14. * Created by roy on 15/8/14.
*/ */
@ -47,7 +75,7 @@ BI.DownListCombo = BI.inherit(BI.Widget, {
ref: function (ref) { ref: function (ref) {
self.popupView = ref; self.popupView = ref;
}, },
items: o.items, items: transformItems(o.items),
chooseType: o.chooseType, chooseType: o.chooseType,
value: o.value, value: o.value,
listeners: [{ listeners: [{
@ -108,3 +136,4 @@ BI.DownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.down_list_combo", BI.DownListCombo); BI.shortcut("bi.down_list_combo", BI.DownListCombo);
}());

Loading…
Cancel
Save