开发者

Why the model can not be added to collection in BackboneJS

window.NCollection = Backbone.Collection.extend({
    url:    '/api/all',
    mod开发者_运维问答el: N,

    parse: function(data){
        var that = this;
        _.each(data, function(item){
            switch(item.cat){
            case 't1':
                console.log(new Note(item));
                that.add(new Type1(item));

                break;
            case 't2':
                that.add(new Type2(item));
                break;
            default:
                that.add(new T(item));
            }
        });
    },

    nextOrder: function() {
      if (!this.length) return 1;
      return this.last().get('id') + 1;
    },

});

I fetch the data of the collection when the page loading. But the collection length also be 0.


And my own question, the return should be added.

parse : function(data) {
  .............
  return data;
},
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜