Procházet zdrojové kódy

fix #1299, correct the loop counter

evantre před 10 roky
rodič
revize
15d567eb59

+ 1 - 0
src/directives/model/select.js

@@ -103,6 +103,7 @@ function initOptions (expression) {
             parentNode.removeChild(option)
           } else {
             el.removeChild(parentNode)
+            i = el.options.length
           }
         }
       }

+ 29 - 2
test/unit/specs/directives/model_spec.js

@@ -373,10 +373,10 @@ if (_.inBrowser) {
       _.nextTick(function () {
         expect(el.firstChild.innerHTML).toBe(
           '<optgroup label="X">' +
-          '<option value="x">x</option><option value="y">y</option>' +
+            '<option value="x">x</option><option value="y">y</option>' +
           '</optgroup>' +
           '<optgroup label="Y">' +
-          '<option value="z">z</option>' +
+            '<option value="z">z</option>' +
           '</optgroup>'
         )
         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: '<select v-model="test" options="opts"><option value=""></option></select>'
+      })
+      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,