Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 集合上的主干更改事件,为什么它有效?_Json_Events_Backbone.js - Fatal编程技术网

Json 集合上的主干更改事件,为什么它有效?

Json 集合上的主干更改事件,为什么它有效?,json,events,backbone.js,Json,Events,Backbone.js,为什么事件“更改”对模型注释1有效?如何修复它?如果我删除行('comment':[]), 事件“改变”不起作用。 我明白这是因为我使用数组,但我需要使用它,但如果他没有任何变化,我就没有事件。谢谢/ 创建新集合 你在做什么会触发一个'change:comment'事件?什么都没有。Json data=模型中的数据,但“更改事件”触发。因此,您或多或少地调用了m.set('comment',[]),它触发了一个“更改”事件,您认为不应该触发该事件?m.set('comment',[])-在获取

为什么事件“更改”对模型注释1有效?如何修复它?如果我删除行('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')
  }
});