mirror of
https://gitee.com/vuejs/vue.git
synced 2024-11-30 02:57:43 +08:00
handle v-repeat switching between object & array (fix #869)
This commit is contained in:
parent
a316dfe9a4
commit
0031c60262
@ -522,8 +522,9 @@ module.exports = {
|
||||
uncacheVm: function (vm) {
|
||||
var data = vm._raw
|
||||
var idKey = this.idKey
|
||||
if (idKey || this.converted) {
|
||||
var id = idKey ? data[idKey] : vm.$key
|
||||
var convertedKey = vm.$key
|
||||
if (idKey || convertedKey) {
|
||||
var id = idKey ? data[idKey] : convertedKey
|
||||
this.cache[id] = null
|
||||
} else if (isObject(data)) {
|
||||
data[this.id] = null
|
||||
@ -573,6 +574,7 @@ function objToArray (obj) {
|
||||
// regardless of type, store the un-filtered raw value.
|
||||
this.rawValue = obj
|
||||
if (!isPlainObject(obj)) {
|
||||
this.converted = false
|
||||
return obj
|
||||
}
|
||||
var keys = Object.keys(obj)
|
||||
|
@ -670,6 +670,32 @@ if (_.inBrowser) {
|
||||
}
|
||||
})
|
||||
|
||||
it('switch between object-converted & array mode', function (done) {
|
||||
var obj = {
|
||||
a: { msg: 'AA' },
|
||||
b: { msg: 'BB' }
|
||||
}
|
||||
var arr = [obj.b, obj.a]
|
||||
var vm = new Vue({
|
||||
el: el,
|
||||
template: '<div v-repeat="obj">{{msg}}</div>',
|
||||
data: {
|
||||
obj: obj
|
||||
}
|
||||
})
|
||||
expect(el.innerHTML).toBe(Object.keys(obj).map(function (key) {
|
||||
return '<div>' + obj[key].msg + '</div>'
|
||||
}).join(''))
|
||||
vm.obj = arr
|
||||
_.nextTick(function () {
|
||||
expect(el.innerHTML).toBe('<div>BB</div><div>AA</div>')
|
||||
// make sure it cleared the cache
|
||||
expect(vm._directives[0].cache.a).toBeNull()
|
||||
expect(vm._directives[0].cache.b).toBeNull()
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user