开发者

Why the model can not be added to collection in BackboneJS

开发者 https://www.devze.com 2023-04-06 23:52 出处:网络
window.NCollection = Backbone.Collection.extend({ url:\'/api/all\', mod开发者_运维问答el: N, parse: function(data){
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

精彩评论

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

关注公众号