From 411d3d2b593788820f009c8c3b6ce01d608d267e Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 21 Sep 2021 00:39:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8watch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/dev.html | 32 ++++++++++++----- examples/resize.html | 73 ++++++++++++++++++++++++++++++++++++++ src/core/4.widget.js | 8 ++--- src/core/wrapper/layout.js | 10 ++++++ 4 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 examples/resize.html diff --git a/examples/dev.html b/examples/dev.html index 3da8b21c9..092b90c16 100644 --- a/examples/dev.html +++ b/examples/dev.html @@ -12,7 +12,7 @@ var Model = BI.inherit(Fix.Model, { state: function () { return { - count: 0 + columnSize: [200, "fill"] }; } }); @@ -20,6 +20,10 @@ BI.model("demo.model", Model); var Widget = BI.inherit(BI.Widget, { + props: { + height: 200, + width: 600 + }, _store: function () { return BI.Models.getModel("demo.model"); }, @@ -27,15 +31,27 @@ var store = BI.useStore(); return function () { return { - type: "bi.vertical", + type: "bi.htape", + columnSize: function () { + return store.model.columnSize; + }, items: [{ - type: "bi.button", - effect: function () { - this.setText(store.model.count) - }, - handler: function () { - store.model.count++; + type: "bi.label", + css: { + background: "#eee" } + }, { + type: "bi.center_adapt", + css: { + background: "#e0e0e0" + }, + items: [{ + type: "bi.button", + text: "点击", + handler: function () { + store.model.columnSize = [300, "fill"] + } + }] }] }; }; diff --git a/examples/resize.html b/examples/resize.html new file mode 100644 index 000000000..5bd99a35d --- /dev/null +++ b/examples/resize.html @@ -0,0 +1,73 @@ + + + + + + + + +
+ + + diff --git a/src/core/4.widget.js b/src/core/4.widget.js index 627128265..29ea02322 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -163,7 +163,7 @@ } if (o.cls) { if (BI.isFunction(o.cls)) { - var cls = this.__watch(o.cls, function (newValue) { + var cls = this.__watch(o.cls, function (context, newValue) { self.element.removeClass(cls).addClass(cls = newValue); }); this.element.addClass(cls); @@ -182,7 +182,7 @@ } if (o.css) { if (BI.isFunction(o.css)) { - var css = this.__watch(o.css, function (newValue) { + var css = this.__watch(o.css, function (context, newValue) { for (var k in css) { if (!newValue[k]) { newValue[k] = ""; @@ -205,8 +205,8 @@ this._watchers = this._watchers || []; var watcher = new Fix.Watcher(null, function () { return getter.call(self, self); - }, (handler && function () { - handler.call(self, self); + }, (handler && function (v) { + handler.call(self, self, v); }) || BI.emptyFn, options); this._watchers.push(watcher); return watcher.value; diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index 1f92a98d1..b147ae9fe 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -19,8 +19,18 @@ BI.Layout = BI.inherit(BI.Widget, { }, render: function () { + var self = this, o = this.options; this._init4Margin(); this._init4Scroll(); + if (BI.isFunction(o.columnSize)) { + var columnSizeFn = o.columnSize; + o.columnSize = this.__watch(columnSizeFn, function (context, newValue) { + o.columnSize = newValue; + self.resize(); + }, { + deep: true + }); + } }, _init4Margin: function () {