From 15d567eb5985e70f80a2a4398465324151c84140 Mon Sep 17 00:00:00 2001 From: evantre Date: Sat, 12 Sep 2015 01:01:09 +0800 Subject: [PATCH] fix #1299, correct the loop counter --- src/directives/model/select.js | 1 + test/unit/specs/directives/model_spec.js | 31 ++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/directives/model/select.js b/src/directives/model/select.js index 7cb3d9a244d..4a4a4316bae 100644 --- a/src/directives/model/select.js +++ b/src/directives/model/select.js @@ -103,6 +103,7 @@ function initOptions (expression) { parentNode.removeChild(option) } else { el.removeChild(parentNode) + i = el.options.length } } } diff --git a/test/unit/specs/directives/model_spec.js b/test/unit/specs/directives/model_spec.js index 1661e00d273..d80d6d849ce 100644 --- a/test/unit/specs/directives/model_spec.js +++ b/test/unit/specs/directives/model_spec.js @@ -373,10 +373,10 @@ if (_.inBrowser) { _.nextTick(function () { expect(el.firstChild.innerHTML).toBe( '' + - '' + + '' + '' + '' + - '' + + '' + '' ) var opts = el.firstChild.options @@ -387,6 +387,33 @@ if (_.inBrowser) { }) }) + it('select + options + optgroup + default option', function (done) { + var vm = new Vue({ + el: el, + data: { + test: '', + opts: [ + { label: 'A', options: ['a', 'b'] }, + { label: 'B', options: ['c'] } + ] + }, + template: '' + }) + var opts = el.firstChild.options + expect(opts[0].selected).toBe(true) + expect(el.firstChild.value).toBe('') + vm.opts = [ + { label: 'X', options: ['x', 'y'] }, + { label: 'Y', options: ['z'] } + ] + _.nextTick(function () { + var opts = el.firstChild.options + expect(opts[0].selected).toBe(true) + expect(el.firstChild.value).toBe('') + done() + }) + }) + it('select + options with Object value', function (done) { var vm = new Vue({ el: el,