I have a backbone app set up that allows me to list a collection of mongodb objects in a table, each with an Edit button next to them. When the Edit button is clicked, an editItem Backbone.View calls its render() function. The user then can change the values and hit a save button. The save button saves the new values to the database just fine, however in the save() success callback function I tried rendering the list view again so that the new values can be viewed. This also works except that since I rendered the view programatically instead of using routes, the URL in the address bar still shows:
http://localhost:3000/#/edit/5199180b2908cbb60b000003
But really I want it to go back to just
http://localhost:3000/
which is just the listview of all the items.
In addition to this, if I attempt to click the Edit button for the SAME item, nothing happens at all anymore, but if I click Edit to any other item, everything works fine. So for some reason, the last edited item is cannot be edited again. here is my code for the save function that is emitted when the save button is clicked.
save :function(e){
console.log("Saving skill");
var btn = e.target;
var id = $('#skillId').val();
var obj = {
name: $('#skillName').val(),
value: $('#skillValue').val()};
var updatedSkill = new SkillModel({"_id":id});
updatedSkill.fetch();
updatedSkill.set(obj);
updatedSkill.save(null,
{
success: function (model, response) {
console.log("success");
skillsview.render();
},
error: function (model, response) {
console.log("error");
}
});
return true;
}
What is the correct way to re-emit a view like this?
I figured it out. It was really simple, just needed:
app_router.navigate('/', {trigger:true});
instead of:
skillsview.render();