diff --git a/src/directives/public/for.js b/src/directives/public/for.js index 4efad312205..a84bba8c62f 100644 --- a/src/directives/public/for.js +++ b/src/directives/public/for.js @@ -485,7 +485,6 @@ module.exports = { */ _postProcess: function (value) { - this.processedValue = value if (_.isArray(value)) { return value } else if (_.isPlainObject(value)) { @@ -523,25 +522,9 @@ module.exports = { frag.destroy() } } - }, - - _syncChanges: function (scope, value) { - // two-way sync for v-for alias - var subjectValue = this.filters ? this.processedValue - : this.rawValue - if (scope.$key) { // original is an object - subjectValue[scope.$key] = value - } else { - subjectValue.$set(scope.$index, value) - } - if (this.filters) { - var vm = this._scope || this.vm - var reverseValue = vm._applyFilters(subjectValue, - subjectValue, this.filters, true) - vm.$set(this.expression, reverseValue) - } } } + /** * Helper to find the previous element that is a fragment * anchor. This is necessary because a destroyed frag's diff --git a/src/instance/misc.js b/src/instance/misc.js index c5db2475c32..7eee2e717f4 100644 --- a/src/instance/misc.js +++ b/src/instance/misc.js @@ -39,17 +39,6 @@ exports._applyFilters = function (value, oldValue, filters, write) { return value } -exports._syncChanges = function (value, expression) { - // two-way sync for v-for alias - var forContext = this.$forContext - if (forContext && forContext.alias === expression) { - var self = this - forContext._withLock(function () { - forContext._syncChanges(self, value) - }) - } -} - /** * Resolve a component, depending on whether the component * is defined normally or using an async factory function. diff --git a/src/watcher.js b/src/watcher.js index 6977c5d8d2c..0adfcc3c850 100644 --- a/src/watcher.js +++ b/src/watcher.js @@ -143,7 +143,27 @@ Watcher.prototype.set = function (value) { ) } } - scope._syncChanges(value, this.expression) + // two-way sync for v-for alias + var forContext = scope.$forContext + if (forContext && forContext.alias === this.expression) { + if (forContext.filters) { + process.env.NODE_ENV !== 'production' && _.warn( + 'It seems you are using two-way binding on ' + + 'a v-for alias (' + this.expression + '), and the ' + + 'v-for has filters. This will not work properly. ' + + 'Either remove the filters or use an array of ' + + 'objects and bind to object properties instead.' + ) + return + } + forContext._withLock(function () { + if (scope.$key) { // original is an object + forContext.rawValue[scope.$key] = value + } else { + forContext.rawValue.$set(scope.$index, value) + } + }) + } } /** diff --git a/test/unit/specs/directives/public/for/for_spec.js b/test/unit/specs/directives/public/for/for_spec.js index 681cfd1e7c6..a9f80545eed 100644 --- a/test/unit/specs/directives/public/for/for_spec.js +++ b/test/unit/specs/directives/public/for/for_spec.js @@ -730,32 +730,19 @@ if (_.inBrowser) { } }) - it('v-model on alias with filters', function (done) { + it('warn v-model on alias with filters', function () { var vm = new Vue({ el: el, template: - '