Browse Source

Pull request #2533: 无JIRA任务 feature: items和value支持自动watch

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

* commit '2787ac97e5df6a4eb4960d7ac8945aab006910b1':
  feature: items和value支持自动watch
es6
guy 3 years ago
parent
commit
ab6554b1dc
  1. 25
      src/base/collection/collection.js
  2. 12
      src/base/combination/group.button.js
  3. 12
      src/base/combination/group.virtual.js
  4. 8
      src/base/combination/loader.js
  5. 6
      src/base/combination/navigation.js
  6. 6
      src/base/combination/tab.js
  7. 25
      src/base/grid/grid.js
  8. 3
      src/base/list/listview.js
  9. 3
      src/base/list/virtualgrouplist.js
  10. 3
      src/base/list/virtuallist.js
  11. 3
      src/base/single/0.single.js
  12. 2
      src/base/single/1.text.js
  13. 4
      src/base/single/text.pure.js
  14. 12
      src/core/4.widget.js
  15. 4
      src/core/wrapper/layout.js

25
src/base/collection/collection.js

@ -11,6 +11,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
baseCls: "bi-collection",
// width: 400, //必设
// height: 300, //必设
scrollable: true,
scrollx: false,
scrolly: false,
overflowX: true,
overflowY: true,
cellSizeAndPositionGetter: BI.emptyFn,
@ -49,14 +52,30 @@ BI.CollectionView = BI.inherit(BI.Widget, {
scrollTop: o.scrollTop
});
});
// 兼容一下
var scrollable = o.scrollable, scrollx = o.scrollx, scrolly = o.scrolly;
if (overflowX === false) {
if (overflowY === false) {
scrollable = false;
} else {
scrollable = "y"
}
} else {
if (overflowY === false) {
scrollable = "x";
}
}
BI._lazyCreateWidget({
type: "bi.vertical",
element: this,
scrollable: o.overflowX === true && o.overflowY === true,
scrolly: o.overflowX === false && o.overflowY === true,
scrollx: o.overflowX === true && o.overflowY === false,
scrollable: scrollable,
scrolly: scrolly,
scrollx: scrollx,
items: [this.container]
});
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
if (o.items.length > 0) {
this._calculateSizeAndPositionData();
this._populate();

12
src/base/combination/group.button.js

@ -21,7 +21,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
},
render: function () {
var o = this.options;
var self = this, o = this.options;
var behaviors = {};
BI.each(o.behaviors, function (key, rule) {
behaviors[key] = BI.BehaviorFactory.createBehavior(key, {
@ -29,7 +29,15 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
});
});
this.behaviors = behaviors;
this.populate(o.items);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
this.populate(items);
if (BI.isFunction(o.value)) {
this.__watch(o.value, function (context, newValue) {
self.setValue(newValue);
})
}
if (BI.isKey(o.value) || BI.isNotEmptyArray(o.value)) {
this.setValue(o.value);
}

12
src/base/combination/group.virtual.js

@ -12,8 +12,16 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
},
render: function () {
var o = this.options;
this.populate(o.items);
var self = this, o = this.options;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
this.populate(items);
if (BI.isFunction(o.value)) {
this.__watch(o.value, function (context, newValue) {
self.setValue(newValue);
})
}
if (BI.isKey(o.value)) {
this.setValue(o.value);
}

8
src/base/combination/loader.js

@ -109,8 +109,11 @@ BI.Loader = BI.inherit(BI.Widget, {
o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () {
o.isDefaultInit && BI.isEmpty(o.items) && this._populate();
}, this));
if (BI.isNotEmptyArray(o.items)) {
this._populate(o.items);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
if (BI.isNotEmptyArray(items)) {
this._populate(items);
}
},
@ -162,7 +165,6 @@ BI.Loader = BI.inherit(BI.Widget, {
this.button_group.addItems.apply(this.button_group, arguments);
},
_populate: function (items) {
var self = this, o = this.options;
if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) {

6
src/base/combination/navigation.js

@ -50,6 +50,12 @@ BI.Navigation = BI.inherit(BI.Widget, {
afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this)
});
if (BI.isFunction(o.showIndex)) {
this.__watch(o.showIndex, function (context, newValue) {
self.setSelect(newValue);
})
}
},
created: function () {

6
src/base/combination/tab.js

@ -54,6 +54,12 @@ BI.Tab = BI.inherit(BI.Widget, {
listener.on(BI.ShowListener.EVENT_CHANGE, function (value) {
self.fireEvent(BI.Tab.EVENT_CHANGE, value, self);
});
if (BI.isFunction(o.showIndex)) {
this.__watch(o.showIndex, function (context, newValue) {
self.setSelect(newValue);
})
}
},
_deleteOtherCards: function (currCardName) {

25
src/base/grid/grid.js

@ -11,6 +11,9 @@ BI.GridView = BI.inherit(BI.Widget, {
baseCls: "bi-grid-view",
// width: 400, //必设
// height: 300, //必设
scrollable: true,
scrollx: false,
scrolly: false,
overflowX: true,
overflowY: true,
overscanColumnCount: 0,
@ -52,14 +55,30 @@ BI.GridView = BI.inherit(BI.Widget, {
scrollTop: o.scrollTop
});
});
// 兼容一下
var scrollable = o.scrollable, scrollx = o.scrollx, scrolly = o.scrolly;
if (overflowX === false) {
if (overflowY === false) {
scrollable = false;
} else {
scrollable = "y"
}
} else {
if (overflowY === false) {
scrollable = "x";
}
}
BI._lazyCreateWidget({
type: "bi.vertical",
element: this,
scrollable: o.overflowX === true && o.overflowY === true,
scrolly: o.overflowX === false && o.overflowY === true,
scrollx: o.overflowX === true && o.overflowY === false,
scrollable: scrollable,
scrolly: scrolly,
scrollx: scrollx,
items: [this.container]
});
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
if (o.items.length > 0) {
this._calculateSizeAndPositionData();
this._populate();

3
src/base/list/listview.js

@ -44,6 +44,9 @@ BI.ListView = BI.inherit(BI.Widget, {
// mounted之后绑定事件
mounted: function () {
var self = this, o = this.options;
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
this._populate();
this.element.scroll(function (e) {
o.scrollTop = self.element.scrollTop();

3
src/base/list/virtualgrouplist.js

@ -57,6 +57,9 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
// mounted之后绑定事件
mounted: function () {
var self = this, o = this.options;
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
this._populate();
this.element.scroll(BI.debounce(function (e) {
o.scrollTop = self.element.scrollTop();

3
src/base/list/virtuallist.js

@ -53,6 +53,9 @@ BI.VirtualList = BI.inherit(BI.Widget, {
// mounted之后绑定事件
mounted: function () {
var self = this, o = this.options;
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue);
}) : o.items;
this._populate();
this.element.scroll(function (e) {
o.scrollTop = self.element.scrollTop();

3
src/base/single/0.single.js

@ -55,6 +55,9 @@ BI.Single = BI.inherit(BI.Widget, {
container: o.container
});
}
o.value = BI.isFunction(o.value) ? this.__watch(o.value, function (context, newValue) {
self.setValue(newValue);
}) : o.value;
},
_clearTimeOut: function () {

2
src/base/single/1.text.js

@ -78,8 +78,6 @@
var text = BI.isFunction(o.text) ? this.__watch(o.text, function (context, newValue) {
self.setText(newValue);
}, {
deep: true
}) : o.text;
// 只要不是undefined就可以显示text值,否则显示value
if (!BI.isUndefined(text)) {

4
src/base/single/text.pure.js

@ -10,7 +10,9 @@
render: function () {
var self = this, o = this.options;
var text = this._getShowText();
var text = BI.isFunction(o.text) ? this.__watch(o.text, function (context, newValue) {
self.setText(newValue);
}) : o.text;
if (BI.isKey(text)) {
this.setText(text);
} else if (BI.isKey(o.value)) {

12
src/core/4.widget.js

@ -224,8 +224,6 @@
}
}
self.element.css(css = newValue);
}, {
deep: true
});
this.element.css(css);
} else {
@ -242,7 +240,7 @@
return getter.call(self, self);
}, (handler && function (v) {
handler.call(self, self, v);
}) || BI.emptyFn, options);
}) || BI.emptyFn, BI.extend({deep: true}, options));
this._watchers.push(watcher);
return watcher.value;
} else {
@ -312,14 +310,10 @@
if (BI.isArray(o.effect)) {
if (BI.isArray(o.effect[0])) {
BI.each(o.effect, function (i, effect) {
self.__watch(effect[0], effect[1], {
deep: true
});
self.__watch(effect[0], effect[1]);
});
} else {
self.__watch(o.effect[0], o.effect[1], {
deep: true
});
self.__watch(o.effect[0], o.effect[1]);
}
} else {
this.__watch(o.effect);

4
src/core/wrapper/layout.js

@ -29,8 +29,6 @@ BI.Layout = BI.inherit(BI.Widget, {
o.columnSize = this.__watch(columnSizeFn, function (context, newValue) {
o.columnSize = newValue;
self.resize();
}, {
deep: true
});
}
if (BI.isFunction(o.rowSize)) {
@ -38,8 +36,6 @@ BI.Layout = BI.inherit(BI.Widget, {
o.rowSize = this.__watch(rowSizeFn, function (context, newValue) {
o.rowSize = newValue;
self.resize();
}, {
deep: true
});
}
},

Loading…
Cancel
Save