From 1f6e01399914ae2b8ed2cbe694ed8bda4e923e53 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 29 Mar 2017 20:25:30 +0800 Subject: [PATCH] add --- bi/base.js | 4 ++- bi/core.js | 40 +++++++++++++++------------- dist/base.js | 4 ++- dist/core.js | 40 +++++++++++++++------------- src/base/combination/group.button.js | 4 ++- src/core/view.js | 8 +++--- src/core/widget.js | 6 +---- src/core/wrapper/layout.js | 26 +++++++++++------- 8 files changed, 75 insertions(+), 57 deletions(-) diff --git a/bi/base.js b/bi/base.js index 100afaa6c..959a0defc 100644 --- a/bi/base.js +++ b/bi/base.js @@ -1020,9 +1020,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { self.setValue([]); break; } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); + } else { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); btn.on(BI.Events.DESTROY, function () { BI.remove(self.buttons, btn); diff --git a/bi/core.js b/bi/core.js index 8e63aed81..dcf943454 100644 --- a/bi/core.js +++ b/bi/core.js @@ -4711,11 +4711,7 @@ BI.Widget = BI.inherit(BI.OB, { removeWidget: function (nameOrWidget) { var self = this; if (BI.isWidget(nameOrWidget)) { - BI.each(this._children, function (name, widget) { - if (widget === nameOrWidget) { - delete self._children[name]; - } - }) + BI.remove(this._children, nameOrWidget); } else { delete this._children[nameOrWidget]; } @@ -5607,7 +5603,7 @@ BI.View = BI.inherit(BI.V, { } //采用静默方式读数据,该数据变化不引起data的change事件触发 var success = options.success; - this.read(BI.extend({ + this.model.read(BI.extend({ silent: true }, options, { success: function (data, model) { @@ -5652,7 +5648,7 @@ BI.View = BI.inherit(BI.V, { reading: function (options) { var self = this; var name = BI.UUID(); - this.read(BI.extend({}, options, { + this.model.read(BI.extend({}, options, { beforeSend: function () { var loading = BI.createWidget({ type: 'bi.vertical', @@ -5675,7 +5671,7 @@ BI.View = BI.inherit(BI.V, { updating: function (options) { var self = this; var name = BI.UUID(); - this.update(BI.extend({}, options, { + this.model.update(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ @@ -5699,7 +5695,7 @@ BI.View = BI.inherit(BI.V, { patching: function (options) { var self = this; var name = BI.UUID(); - this.patch(BI.extend({}, options, { + this.model.patch(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ @@ -11261,6 +11257,7 @@ BI.Layout = BI.inherit(BI.Widget, { w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { + BI.remove(self._children, child); self.removeItemAt(name | 0); } }); @@ -11414,7 +11411,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (var i = 0, len = this.options.items.length; i < len; i++) { var child = this._children[this._getChildName(i)]; if (indexes.contains(i)) { - deleted.push(child); + child && deleted.push(child); } else { newChildren[this._getChildName(newItems.length)] = child; newItems.push(this.options.items[i]); @@ -11489,26 +11486,32 @@ BI.Layout = BI.inherit(BI.Widget, { }, getValue: function () { - var self = this, value = []; + var self = this, value = [], child; BI.each(this.options.items, function (i) { - var v = self._children[self._getChildName(i)].getValue(); - v = BI.isArray(v) ? v : [v]; - value = value.concat(v); + if (child = self._children[self._getChildName(i)]) { + var v = child.getValue(); + v = BI.isArray(v) ? v : [v]; + value = value.concat(v); + } }); return value; }, setValue: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setValue(v); + if (child = self._children[self._getChildName(i)]) { + child.setValue(v); + } }) }, setText: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setText(v); + if (child = self._children[self._getChildName(i)]) { + child.setText(v); + } }) }, @@ -11525,6 +11528,7 @@ BI.Layout = BI.inherit(BI.Widget, { var deleted = []; for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); + delete this._children[this._getChildName(i)]; } o.items.splice(items.length); BI.each(deleted, function (i, w) { diff --git a/dist/base.js b/dist/base.js index 100afaa6c..959a0defc 100644 --- a/dist/base.js +++ b/dist/base.js @@ -1020,9 +1020,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { self.setValue([]); break; } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); + } else { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); btn.on(BI.Events.DESTROY, function () { BI.remove(self.buttons, btn); diff --git a/dist/core.js b/dist/core.js index dd5cdda0a..2ccd75f2d 100644 --- a/dist/core.js +++ b/dist/core.js @@ -14623,11 +14623,7 @@ BI.Widget = BI.inherit(BI.OB, { removeWidget: function (nameOrWidget) { var self = this; if (BI.isWidget(nameOrWidget)) { - BI.each(this._children, function (name, widget) { - if (widget === nameOrWidget) { - delete self._children[name]; - } - }) + BI.remove(this._children, nameOrWidget); } else { delete this._children[nameOrWidget]; } @@ -15519,7 +15515,7 @@ BI.View = BI.inherit(BI.V, { } //采用静默方式读数据,该数据变化不引起data的change事件触发 var success = options.success; - this.read(BI.extend({ + this.model.read(BI.extend({ silent: true }, options, { success: function (data, model) { @@ -15564,7 +15560,7 @@ BI.View = BI.inherit(BI.V, { reading: function (options) { var self = this; var name = BI.UUID(); - this.read(BI.extend({}, options, { + this.model.read(BI.extend({}, options, { beforeSend: function () { var loading = BI.createWidget({ type: 'bi.vertical', @@ -15587,7 +15583,7 @@ BI.View = BI.inherit(BI.V, { updating: function (options) { var self = this; var name = BI.UUID(); - this.update(BI.extend({}, options, { + this.model.update(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ @@ -15611,7 +15607,7 @@ BI.View = BI.inherit(BI.V, { patching: function (options) { var self = this; var name = BI.UUID(); - this.patch(BI.extend({}, options, { + this.model.patch(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ @@ -19394,6 +19390,7 @@ BI.Layout = BI.inherit(BI.Widget, { w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { + BI.remove(self._children, child); self.removeItemAt(name | 0); } }); @@ -19547,7 +19544,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (var i = 0, len = this.options.items.length; i < len; i++) { var child = this._children[this._getChildName(i)]; if (indexes.contains(i)) { - deleted.push(child); + child && deleted.push(child); } else { newChildren[this._getChildName(newItems.length)] = child; newItems.push(this.options.items[i]); @@ -19622,26 +19619,32 @@ BI.Layout = BI.inherit(BI.Widget, { }, getValue: function () { - var self = this, value = []; + var self = this, value = [], child; BI.each(this.options.items, function (i) { - var v = self._children[self._getChildName(i)].getValue(); - v = BI.isArray(v) ? v : [v]; - value = value.concat(v); + if (child = self._children[self._getChildName(i)]) { + var v = child.getValue(); + v = BI.isArray(v) ? v : [v]; + value = value.concat(v); + } }); return value; }, setValue: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setValue(v); + if (child = self._children[self._getChildName(i)]) { + child.setValue(v); + } }) }, setText: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setText(v); + if (child = self._children[self._getChildName(i)]) { + child.setText(v); + } }) }, @@ -19658,6 +19661,7 @@ BI.Layout = BI.inherit(BI.Widget, { var deleted = []; for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); + delete this._children[this._getChildName(i)]; } o.items.splice(items.length); BI.each(deleted, function (i, w) { diff --git a/src/base/combination/group.button.js b/src/base/combination/group.button.js index d4d7ad278..353f18cd0 100644 --- a/src/base/combination/group.button.js +++ b/src/base/combination/group.button.js @@ -57,9 +57,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, { self.setValue([]); break; } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); + } else { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); btn.on(BI.Events.DESTROY, function () { BI.remove(self.buttons, btn); diff --git a/src/core/view.js b/src/core/view.js index baac6b554..c0ae68237 100644 --- a/src/core/view.js +++ b/src/core/view.js @@ -327,7 +327,7 @@ BI.View = BI.inherit(BI.V, { } //采用静默方式读数据,该数据变化不引起data的change事件触发 var success = options.success; - this.read(BI.extend({ + this.model.read(BI.extend({ silent: true }, options, { success: function (data, model) { @@ -372,7 +372,7 @@ BI.View = BI.inherit(BI.V, { reading: function (options) { var self = this; var name = BI.UUID(); - this.read(BI.extend({}, options, { + this.model.read(BI.extend({}, options, { beforeSend: function () { var loading = BI.createWidget({ type: 'bi.vertical', @@ -395,7 +395,7 @@ BI.View = BI.inherit(BI.V, { updating: function (options) { var self = this; var name = BI.UUID(); - this.update(BI.extend({}, options, { + this.model.update(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ @@ -419,7 +419,7 @@ BI.View = BI.inherit(BI.V, { patching: function (options) { var self = this; var name = BI.UUID(); - this.patch(BI.extend({}, options, { + this.model.patch(BI.extend({}, options, { noset: true, beforeSend: function () { var loading = BI.createWidget({ diff --git a/src/core/widget.js b/src/core/widget.js index 7c478c31d..693734fc9 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -288,11 +288,7 @@ BI.Widget = BI.inherit(BI.OB, { removeWidget: function (nameOrWidget) { var self = this; if (BI.isWidget(nameOrWidget)) { - BI.each(this._children, function (name, widget) { - if (widget === nameOrWidget) { - delete self._children[name]; - } - }) + BI.remove(this._children, nameOrWidget); } else { delete this._children[nameOrWidget]; } diff --git a/src/core/wrapper/layout.js b/src/core/wrapper/layout.js index f4f76a5c0..cf23c3974 100644 --- a/src/core/wrapper/layout.js +++ b/src/core/wrapper/layout.js @@ -74,6 +74,7 @@ BI.Layout = BI.inherit(BI.Widget, { w.on(BI.Events.DESTROY, function () { BI.each(self._children, function (name, child) { if (child === w) { + BI.remove(self._children, child); self.removeItemAt(name | 0); } }); @@ -227,7 +228,7 @@ BI.Layout = BI.inherit(BI.Widget, { for (var i = 0, len = this.options.items.length; i < len; i++) { var child = this._children[this._getChildName(i)]; if (indexes.contains(i)) { - deleted.push(child); + child && deleted.push(child); } else { newChildren[this._getChildName(newItems.length)] = child; newItems.push(this.options.items[i]); @@ -302,26 +303,32 @@ BI.Layout = BI.inherit(BI.Widget, { }, getValue: function () { - var self = this, value = []; + var self = this, value = [], child; BI.each(this.options.items, function (i) { - var v = self._children[self._getChildName(i)].getValue(); - v = BI.isArray(v) ? v : [v]; - value = value.concat(v); + if (child = self._children[self._getChildName(i)]) { + var v = child.getValue(); + v = BI.isArray(v) ? v : [v]; + value = value.concat(v); + } }); return value; }, setValue: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setValue(v); + if (child = self._children[self._getChildName(i)]) { + child.setValue(v); + } }) }, setText: function (v) { - var self = this; + var self = this, child; BI.each(this.options.items, function (i) { - self._children[self._getChildName(i)].setText(v); + if (child = self._children[self._getChildName(i)]) { + child.setText(v); + } }) }, @@ -338,6 +345,7 @@ BI.Layout = BI.inherit(BI.Widget, { var deleted = []; for (i = items.length; i < o.items.length; i++) { deleted.push(this._children[this._getChildName(i)]); + delete this._children[this._getChildName(i)]; } o.items.splice(items.length); BI.each(deleted, function (i, w) {