Explorar el Código

fix #707: v-repeat nested repeats on object

calebboyd hace 11 años
padre
commit
7b7c2e57cf
Se han modificado 2 ficheros con 23 adiciones y 1 borrados
  1. 1 1
      src/directives/repeat.js
  2. 22 0
      test/unit/specs/directives/repeat_spec.js

+ 1 - 1
src/directives/repeat.js

@@ -268,7 +268,7 @@ module.exports = {
     }
     var raw = this.converted ? data.value : data
     var alias = this.arg
-    var hasAlias = !isPlainObject(raw) || alias
+    var hasAlias = !isObject(raw) || !isPlainObject(data) || alias
     // wrap the raw data with alias
     data = hasAlias ? {} : raw
     if (alias) {

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

@@ -194,6 +194,28 @@ if (_.inBrowser) {
       )
     })
 
+    it('nested repeats on object', function(){
+      var vm = new Vue({
+        el: el,
+        data: {
+          listHash: {
+            listA: [{a: 1},{a: 2}],
+            listB: [{a: 1},{a: 2}]
+          }
+        },
+        template: '<div v-repeat="listHash">{{$key}}' +
+            '<p v-repeat="$data">{{a}}</p>' +
+            '</div>'
+      })
+      function output(key){
+        var key1 = key === 'listA' ? 'listB' : 'listA'
+        return  '<div>'+ key +'<p>1</p><p>2</p><!--v-repeat--></div>' +
+                '<div>'+ key1 +'<p>1</p><p>2</p><!--v-repeat--></div>' +
+                '<!--v-repeat-->'
+      }
+      expect(el.innerHTML === output('listA') || el.innerHTML === output('listB')).toBeTruthy()
+    })
+
     it('dynamic component type based on instance data', function () {
       var vm = new Vue({
         el: el,