Json 集合上的主干更改事件,为什么它有效?
为什么事件“更改”对模型注释1有效?如何修复它?如果我删除行('comment':[]), 事件“改变”不起作用。 我明白这是因为我使用数组,但我需要使用它,但如果他没有任何变化,我就没有事件。谢谢/Json 集合上的主干更改事件,为什么它有效?,json,events,backbone.js,Json,Events,Backbone.js,为什么事件“更改”对模型注释1有效?如何修复它?如果我删除行('comment':[]), 事件“改变”不起作用。 我明白这是因为我使用数组,但我需要使用它,但如果他没有任何变化,我就没有事件。谢谢/ 创建新集合 你在做什么会触发一个'change:comment'事件?什么都没有。Json data=模型中的数据,但“更改事件”触发。因此,您或多或少地调用了m.set('comment',[]),它触发了一个“更改”事件,您认为不应该触发该事件?m.set('comment',[])-在获取
创建新集合
你在做什么会触发一个
'change:comment'
事件?什么都没有。Json data=模型中的数据,但“更改事件”触发。因此,您或多或少地调用了m.set('comment',[])
,它触发了一个“更改”
事件,您认为不应该触发该事件?m.set('comment',[])-在获取之前,在获取之后数组注释未更改。。也许我解释了事实并非如此,我的英语也不是很好,但非常感谢你的帮助。这个系列的模型是什么样子的?它有默认值吗?
var commentCollection = new VPRS.Comment.CommentCollection([
{
"id": "comment1",
"questionId": "post1",
"name": "Alex",
"text": "text 1",
"comment":[]
},
{
"id": "comment2",
"questionId": "post1",
"name": "Alex",
"text": "Text2"
}
]);
----------
json = [
{
"id": "comment1",
"questionId": "post1",
"name": "Alex",
"text": "text 1",
"comment":[]
},
{
"id": "comment2",
"questionId": "post1",
"name": "Alex",
"text": "Text2"
}]
--------------
wallItemCollection.on('change', function (model) {
console.log('model change')
}
------------
wallItemCollection.fetch({
update: true,
merge: true,
success: function () {
console.log('fetch compleate')
}
});