Skip to content

Commit c289a7e

Browse files
committed
make v-model checkbox updates replace the bound array (fix #3307)
1 parent f9ac406 commit c289a7e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/directives/public/model/checkbox.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ export default {
3131
}
3232

3333
this.listener = function () {
34-
var model = self._watcher.value
34+
var model = self._watcher.get()
3535
if (isArray(model)) {
3636
var val = self.getValue()
37+
var i = indexOf(model, val)
3738
if (el.checked) {
38-
if (indexOf(model, val) < 0) {
39-
model.push(val)
39+
if (i < 0) {
40+
self.set(model.concat(val))
4041
}
41-
} else {
42-
model.$remove(val)
42+
} else if (i > -1) {
43+
self.set(model.slice(0, i).concat(model.slice(i + 1)))
4344
}
4445
} else {
4546
self.set(getBooleanValue())

test/unit/specs/directives/public/model_spec.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,13 @@ describe('v-model', function () {
185185
el.firstChild.click()
186186
expect(vm.list.length).toBe(2)
187187
expect(vm.list[1]).toBe(1)
188-
vm.list = [vm.a]
189188
_.nextTick(function () {
190-
expect(el.firstChild.checked).toBe(false)
191-
expect(el.lastChild.checked).toBe(true)
192-
done()
189+
vm.list = [vm.a]
190+
_.nextTick(function () {
191+
expect(el.firstChild.checked).toBe(false)
192+
expect(el.lastChild.checked).toBe(true)
193+
done()
194+
})
193195
})
194196
})
195197

0 commit comments

Comments
 (0)