【发布时间】:2012-01-19 11:08:12
【问题描述】:
使用backbone.js...
@model.bind 'change', ()-> console.log 'updated'
addIndex = (index) =>
array = @model.get('array')
array.push index
@model.set
array: array
这会完美地更新模型,但不会触发更改事件。有谁知道我发布的内容为什么?
编辑:
我添加了这个,它触发了更改事件:
@model.set
test: ''
num = 0
setInterval ()=>
num++
@model.set
test: num
, 3000
我添加了这个,它不会触发更改事件:
@model.set
test: []
num = 0
setInterval ()=>
console.log 'testupdate'
num++
test = @model.get('test')
test.push num
@model.set
test: test
, 3000
【问题讨论】:
-
数组是否被填充?
-
是的,模型更新正常,并且数组正确填充到模型属性中。
标签: javascript jquery backbone.js coffeescript