Skip to content

Fix nested repeats with track-by. #783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/directives/repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ module.exports = {
} else { // new instance
vm = this.build(obj, i, true)
vm._new = true
vm._reused = false
}
vms[i] = vm
// insert if this is first run
Expand Down
54 changes: 54 additions & 0 deletions test/unit/specs/directives/repeat_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,60 @@ if (_.inBrowser) {
})
})

it('nested track by', function (done) {
assertTrackBy('<div v-repeat="list" track-by="id">{{msg}}<div v-repeat="list" track-by="id">{{msg}}</div></div>', function () {
assertTrackBy('<div v-transition v-repeat="list" track-by="id">{{msg}}<div v-transition v-repeat="list" track-by="id">{{msg}}</div></div>', done)
})

function assertTrackBy(template, next) {
var vm = new Vue({
el: el,
data: {
list: [
{ id: 1, msg: 'hi', list: [
{ id: 1, msg: 'hi foo' }
] },
{ id: 2, msg: 'ha', list: [] },
{ id: 3, msg: 'ho', list: [] }
]
},
template: template
})
assertMarkup()

var oldVms = vm._children.slice()

vm.list = [
{ id: 1, msg: 'wa', list: [
{ id: 1, msg: 'hi foo' },
{ id: 2, msg: 'hi bar' }
] },
{ id: 2, msg: 'wo', list: [] }
]

_.nextTick(function () {
assertMarkup()
// should reuse old vms!
var i = 2
while (i--) {
expect(vm._children[i]).toBe(oldVms[i])
}
expect(vm._children[0]._children[0]).toBe(oldVms[0]._children[0])
next()
})

function assertMarkup () {
var markup = vm.list.map(function (item) {
var sublist = item.list.map(function (item) {
return '<div>' + item.msg + '</div>'
}).join('') + '<!--v-repeat-->'
return '<div>' + item.msg + sublist + '</div>'
}).join('') + '<!--v-repeat-->'
expect(el.innerHTML).toBe(markup)
}
}
})

})
}

Expand Down