Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone destroy a model outside of a collection
    primarykey
    data
    text
    <p>I have a <code>UserPanel</code> view, which uses a <code>UserModel</code> as its model. In the template for the <code>UserPanel</code>, I have a conditional that checks whether or not the model is <code>undefined</code>. If the model exists, it displays user information. If it doesn't, it displays the "registration" form.</p> <p>On the user information part of the <code>UserPanel</code>, I have what's essentially an "unregister" button. A user clicks it, and the user information is deleted. The <code>UserPanel</code> responds by re-rendering, allowing them to register a different <code>UserModel</code>.</p> <p>Common sense tells me to call <a href="http://backbonejs.org/#Model-destroy" rel="nofollow">this.model.destroy</a>. When I use this method, my model is deleted from my data store, but the object still exists in <code>this.model</code>. When the view responds to the model update (by calling <code>render</code>), it still thinks it has a valid model, with all its data and the like. I can call delete on <code>this.model</code>, but that doesn't trigger any events. I can't trigger the event before I <code>delete</code>, because then the view updates before I can delete the model. I have setup the view to respond to model deletions with a method that simply uses <code>delete</code> on the model, then calls <code>render</code>. This works, but bothers me on a conceptual level, since those methods are for handling view updates and not more model manipulation.</p> <p>In general, what's the proper way to explicitly dispose of a model that is not stored by a collection?</p> <p>EDIT: I am using <a href="https://github.com/jeromegn/Backbone.localStorage" rel="nofollow">Backbone.localStorage</a> as my data store. This might have something to do with it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload