[英]Remove an attribute from a Backbone.js model
Is there a way to remove an attribute from a Backbone model? 有没有办法从Backbone模型中删除属性?
Reason being is I pass up extra data on save to perform certain actions, but then that data gets automatically added to my model 原因是我在保存时传递额外数据以执行某些操作,但随后该数据会自动添加到我的模型中
The documentation says to not edit the model.attributes directly, so the only other method I see to do this would be to use the set method and set the attribute to null, but that is not ideal 文档说不直接编辑model.attributes,所以我看到的另一个方法就是使用set方法并将属性设置为null,但这并不理想
var myModel = new Model()
myModel.save({name:'Holla', specialAttr:'Please Remove me'})
myModel.set({tempAttr:null})
if(myModel.attributes['specialAttr'] == null){
alert("Model does not have a specialAttr")
}
I've also tried removing it from the attributes property, but it doesn't really remove it. 我也试过从attributes属性中删除它,但它并没有真正删除它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.