Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
179
rated 0 times [  185] [ 6]  / answers: 1 / hits: 28918  / 12 Years ago, tue, may 15, 2012, 12:00:00

Is there a way to remove an attribute from a Backbone model?



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



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.


More From » backbone.js

 Answers
111

Are you looking for model.unset ?




Remove an attribute by deleting it from the internal attributes hash.
Fires a change event unless silent is passed as an option.




You can find the documentation here.


[#85565] Monday, May 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kendellc

Total Points: 84
Total Questions: 97
Total Answers: 102

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;