Skip to content

Commit 315f9a7

Browse files
evantreyyx990803
authored andcommitted
fix #1299, correct the loop counter
1 parent dbaabb2 commit 315f9a7

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/directives/model/select.js

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function initOptions (expression) {
106106
parentNode.removeChild(option)
107107
} else {
108108
el.removeChild(parentNode)
109+
i = el.options.length
109110
}
110111
}
111112
}

test/unit/specs/directives/model_spec.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,10 @@ if (_.inBrowser) {
427427
_.nextTick(function () {
428428
expect(el.firstChild.innerHTML).toBe(
429429
'<optgroup label="X">' +
430-
'<option value="x">x</option><option value="y">y</option>' +
430+
'<option value="x">x</option><option value="y">y</option>' +
431431
'</optgroup>' +
432432
'<optgroup label="Y">' +
433-
'<option value="z">z</option>' +
433+
'<option value="z">z</option>' +
434434
'</optgroup>'
435435
)
436436
var opts = el.firstChild.options
@@ -441,6 +441,33 @@ if (_.inBrowser) {
441441
})
442442
})
443443

444+
it('select + options + optgroup + default option', function (done) {
445+
var vm = new Vue({
446+
el: el,
447+
data: {
448+
test: '',
449+
opts: [
450+
{ label: 'A', options: ['a', 'b'] },
451+
{ label: 'B', options: ['c'] }
452+
]
453+
},
454+
template: '<select v-model="test" options="opts"><option value=""></option></select>'
455+
})
456+
var opts = el.firstChild.options
457+
expect(opts[0].selected).toBe(true)
458+
expect(el.firstChild.value).toBe('')
459+
vm.opts = [
460+
{ label: 'X', options: ['x', 'y'] },
461+
{ label: 'Y', options: ['z'] }
462+
]
463+
_.nextTick(function () {
464+
var opts = el.firstChild.options
465+
expect(opts[0].selected).toBe(true)
466+
expect(el.firstChild.value).toBe('')
467+
done()
468+
})
469+
})
470+
444471
it('select + options with Object value', function (done) {
445472
var vm = new Vue({
446473
el: el,

0 commit comments

Comments
 (0)