关于集合的骨干更改事件,为什么会有效?

时间:2012-12-15 15:25:46

标签: json events backbone.js

为什么事件"改变"适用于模型评论1?如何解决?如果我删除行('评论':[]), 事件'变化'不行。 我明白这是因为我使用数组,但我需要使用它,但我没有事件,如果他没有改变。感谢/


  

创建新集合

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')
  }
});

0 个答案:

没有答案