Better solution for nested Backbone.js collections

前端 未结 4 583
一个人的身影
一个人的身影 2021-01-30 12:04

Many of my Backbone models often deal with nested models and collections, so far I\'m using a combination of defaults, parse and toJSON ma

4条回答
  •  不要未来只要你来
    2021-01-30 12:36

    I don't see any problem with your approach.

    IMHO the Model.parse() method if for this: to be overwritten in case special parse behavior needs.

    The only think I'd change would be things like this:

    if (res.tags) res.tags = new ACME.Tags(res.tags);
    

    For this:

    if (res.tags) this.tags.reset(res.tags);
    

    Due you already have an instance of ACME.Tags collection I'd reuse it.

    Also I don't really like the defaults implementation, I'm used to do this initializations in the Model.initialize() but I think is a matter of taste.

提交回复
热议问题