From fe00ac8ebda576e925d06c55656a27ac208090b8 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 20 Sep 2021 02:33:08 +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 --- src/core/4.widget.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index efe65049d..56ad3a02a 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -164,9 +164,7 @@ if (o.cls) { if (BI.isFunction(o.cls)) { var cls = this.__watch(o.cls, function (newValue) { - if (newValue !== cls) { - self.element.removeClass(cls).addClass(cls = newValue); - } + self.element.removeClass(cls).addClass(cls = newValue); }); this.element.addClass(cls); } else { @@ -191,6 +189,8 @@ } } self.element.css(css = newValue); + }, { + deep: true }); this.element.css(css); } else { @@ -199,10 +199,10 @@ } }, - __watch: function (getter, handler) { + __watch: function (getter, handler, options) { if (Fix.Model.target) { this._watchers = this._watchers || []; - var watcher = new Fix.Watcher(Fix.Model.target, BI.bind(getter, this), handler || BI.emptyFn); + var watcher = new Fix.Watcher(Fix.Model.target, BI.bind(getter, this), handler || BI.emptyFn, options); this._watchers.push(watcher); return watcher.value; } else { @@ -259,7 +259,7 @@ }, _initEffects: function () { - var o = this.options; + var self = this, o = this.options; if (o.disabled || o.invalid) { if (this.options.disabled) { this.setEnable(false); @@ -269,7 +269,21 @@ } } if (o.effect) { - this.__watch(o.effect); + 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 + }); + }); + } else { + self.__watch(o.effect[0], o.effect[1], { + deep: true + }); + } + } else { + this.__watch(o.effect); + } } },