Exclude model properties when syncing (Backbone.js)

后端 未结 11 1402
甜味超标
甜味超标 2020-12-07 14:26

Is there a way to exclude certain property from my model when I sync?

For example, I keep in my model information about some view state. Let\'s say I have a picker m

11条回答
  •  伪装坚强ぢ
    2020-12-07 14:46

    Since save uses toJSON we override it:

        toJSON: function(options) {
            var attr = _.clone(this.attributes);
            delete attr.selected;
            return attr;
        },
    

    But it may not work if you're using toJSON and need selected in views for example. Otherwise you probably need to override save method.

提交回复
热议问题