Backbone.js Handling of Attributes That Are Arrays

后端 未结 4 589
迷失自我
迷失自我 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:09

    Thom Blake is right about why it's keeping the same values for the array. one option for solving this is to set the default value in the initializer

            var Criteria = Backbone.Model.extend({
    
                defaults: {
                    "status": "Normal",
                    "priority": "Normal"
                },
    
                initialize: function(){
                  if( !this.get('tags') ){ 
                    this.set({tags: new Array()});
                  }
                }
    
            });
    

提交回复
热议问题