backbone.js - How do I get a view to refresh after I delete a model from a collection? -


I have a view that is a list of phones. In the list, you can add or remove the phone. For example, for example, the function is called when the deleted phone form is clicked on. The problem is that after the phone is removed, I want to navigate through the updated list. The way I am using the backbone, it means that the phone will need to refresh the collection of phones, but I think it's okay, as long as the list is updated. With the below function, the list is not refreshing.

  deletePhone: function (ev) {var that = this; ev.preventDefault (); Var Phone Delete = $ (Ivorator Target). Serialize object (); Var Phone = New P.phone (); Phone.set ({ID: [phone-to-remove ']}); Phone.destroy ({success: function (model, response, option) {Backbone.history.navigate ('phone', {trigger: true})}}, error: function (model, feedback, option) {console.log ( "In error:");}}); },   

How do I navigate to the updated list?

Once you delete a model within a compilation and delete that model on the server successfully , The model will trigger a 'destroyed' event that will be bubble for collection. This scene is asked to hear the event being destroyed on the archive, and then it happens once again to render. To do this, place this line of code in the initialization function:

  this.listenTo (this.collection, 'delete', this.render);   

Once a model has been removed from the collection, this code will call the renderer function. Note that it is not necessary to get the updated list from the server, because the spinal cord has already been removed from the archive at the front end. Of course, if there is a possibility that the list has been replaced by other customers, it may be necessary to grab it from the server.

This render call may be better than being removed from the function, This cover is in case that a model is removed from the collection through another medium.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -