Ver código fonte

fix v-repeat on array of arrays without identifier

Evan You 11 anos atrás
pai
commit
ab254f7e8f
2 arquivos alterados com 17 adições e 2 exclusões
  1. 3 2
      src/directives/repeat.js
  2. 14 0
      test/unit/specs/directives/repeat_spec.js

+ 3 - 2
src/directives/repeat.js

@@ -1,5 +1,6 @@
 var _ = require('../util')
 var isObject = _.isObject
+var isPlainObject = _.isPlainObject
 var textParser = require('../parsers/text')
 var expParser = require('../parsers/expression')
 var templateParser = require('../parsers/template')
@@ -267,7 +268,7 @@ module.exports = {
     }
     var raw = this.converted ? data.value : data
     var alias = this.arg
-    var hasAlias = !isObject(raw) || alias
+    var hasAlias = !isPlainObject(raw) || alias
     // wrap the raw data with alias
     data = hasAlias ? {} : raw
     if (alias) {
@@ -467,7 +468,7 @@ function findNextVm (vm, ref) {
  */
 
 function objToArray (obj) {
-  if (!_.isPlainObject(obj)) {
+  if (!isPlainObject(obj)) {
     return obj
   }
   var keys = Object.keys(obj)

+ 14 - 0
test/unit/specs/directives/repeat_spec.js

@@ -110,6 +110,20 @@ if (_.inBrowser) {
       assertObjectPrimitiveMutations(vm, el, done)
     })
 
+    it('array of arrays', function () {
+      var vm = new Vue({
+        el: el,
+        data: {
+          items: [[1,1], [2,2], [3,3]]
+        },
+        template: '<div v-repeat="items">{{$index}} {{$value}}</div>'
+      })
+      var markup = vm.items.map(function (item, i) {
+        return '<div>' + i + ' ' + item.toString() + '</div>'
+      }).join('') + '<!--v-repeat-->'
+      expect(el.innerHTML).toBe(markup)
+    })
+
     it('repeating object with filter', function () {
       var vm = new Vue({
         el: el,