Backbone.js Handling of Attributes That Are Arrays

后端 未结 4 591
迷失自我
迷失自我 2020-12-13 06:44

I really like Backbone, but I am having the hardest time doing what would seem to be simple things. I appreciate any help with the following example.

I have a model,

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 07:11

    "defaults" can also be a function.

    var Criteria = Backbone.Model.extend({
        defaults: function () {
            return {
                "status": "Normal",
                "priority": "Normal",
                "tags": new Array()
            }
        }
    });
    

    This would create a new array when a new Criteria is instantiated. See: http://backbonejs.org/#Model-defaults

提交回复
热议问题