From e75e8747bb8fd2a7c809f799ab09f601e8133552 Mon Sep 17 00:00:00 2001 From: "fisher.yu" Date: Thu, 28 Sep 2017 10:44:18 +0800 Subject: [PATCH] =?UTF-8?q?'=E7=BB=84=E4=BB=B6=E4=B8=AD=E6=9C=89=E5=AD=90?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=98=AF=E5=88=97=E8=A1=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=80=BC=E4=B8=BA=E7=A9=BA=E4=BC=9A=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E7=9A=84=E8=A7=A3=E5=86=B3'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/wepy/src/component.js | 46 +++++++++++++--------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/packages/wepy/src/component.js b/packages/wepy/src/component.js index 54cf47afd..e68dae973 100644 --- a/packages/wepy/src/component.js +++ b/packages/wepy/src/component.js @@ -134,10 +134,6 @@ export default class { if (binded) { if (typeof(binded) === 'object') { props[key].repeat = binded.for; - props[key].item = binded.item; - props[key].index = binded.index; - props[key].key = binded.key; - props[key].value = binded.value; inRepeat = true; @@ -149,9 +145,8 @@ export default class { binddata = [{}]; } }); - if (binddata && (typeof binddata === 'object' || typeof binddata === 'string')) { - repeatKey = Object.keys(binddata)[0]; - } + repeatKey = Object.keys(binddata)[0]; + if (!this.$mappingProps[key]) this.$mappingProps[key] = {}; this.$mappingProps[key]['parent'] = { @@ -183,7 +178,7 @@ export default class { } this.$data = util.$copy(this.data, true); - if (inRepeat && repeatKey !== undefined) + if (inRepeat) this.$setIndex(repeatKey); if (this.computed) { @@ -261,6 +256,9 @@ export default class { * 对于在repeat中的组件,index改变时需要修改对应的数据 */ $setIndex (index) { + if (this.$index === index) + return; + this.$index = index; let props = this.props, @@ -283,17 +281,7 @@ export default class { } }); - index = Array.isArray(binddata) ? +index : index; - - if (props[key].value === props[key].item) { - val = binddata[index]; - } else if (props[key].value === props[key].index) { - val = index; - } else if (props[key].value === props[key].key) { - val = index; - } else { - val = $parent[props[key].value]; - } + val = binddata[index]; this.$index = index; this.data[key] = val; this[key] = val; @@ -437,15 +425,6 @@ export default class { this.$$phase = '$digest'; while (this.$$phase) { let readyToSet = {}; - if (this.computed) { - for (k in this.computed) { // If there are computed property, calculated every times - let fn = this.computed[k], val = fn.call(this); - if (!util.$isEqual(this[k], val)) { // Value changed, then send to ReadyToSet - readyToSet[this.$prefix + k] = val; - this[k] = util.$copy(val, true); - } - } - } for (k in originData) { if (!util.$isEqual(this[k], originData[k])) { // compare if new data is equal to original data // data watch trigger @@ -481,6 +460,15 @@ export default class { } } if (Object.keys(readyToSet).length) { + if (this.computed) { + for (k in this.computed) { // If there are computed property, calculated every times + let fn = this.computed[k], val = fn.call(this); + if (!util.$isEqual(this[k], val)) { // Value changed, then send to ReadyToSet + readyToSet[this.$prefix + k] = val; + this[k] = util.$copy(val, true); + } + } + } this.setData(readyToSet); } this.$$phase = (this.$$phase === '$apply') ? '$digest' : false; @@ -503,4 +491,4 @@ function getEventsFn (comContext, evtName) { fnFn = fn; } return fnFn; -} +} \ No newline at end of file