Answer the question
In order to leave comments, you need to log in
The model is not deleted from the previous record?
Good afternoon! Need help implementing post editing (using Backbone). I will describe the essence of the problem.
There is an article section available at site.ru/admin#articles. There is a list of articles. There is an "Edit" button.
If it is clicked, the '*articles/edit/:id' : 'editArticle' route is triggered and the function is called
editArticle: function(articles, id){
require(['models/articles'], function(ArticlesModel){
var Articles = new ArticlesModel({id: id});
Articles.fetch().then(function(){
require(['views/articles/edit'], function(EditArticle){
var editArticle = new EditArticle({model: Articles});
});
});
});
},
define([
'jquery',
'underscore',
'backbone',
'routes/routes',
'text!templates/articles/edit.html'
], function($, _, Backbone, Router, EditArticleTpl){
var EditArticle = Backbone.View.extend({
el: "#element-page",
template: _.template(EditArticleTpl),
events: {
'click #submit_edit_article': 'edit',
},
initialize: function(){
this.render();
},
close: function(){
this.stopListening();
},
render: function(){
this.$el.html(this.template(this.model.toJSON()));
return this;
},
edit: function(){
this.model.save({
title : this.$("#container_edit_article #title").val(),
text : this.$("#container_edit_article #text").val(),
publish : this.$("#container_edit_article #publish").val(),
title_seo : this.$("#container_edit_article #title_seo").val(),
keywords : this.$("#container_edit_article #keywords").val(),
description : this.$("#container_edit_article #description").val(),
}, {validate : true});
// Перенаправляет на другую страницу
var router = new Router();
router.navigate("articles", true);
},
});
return EditArticle;
});
Answer the question
In order to leave comments, you need to log in
You have zombie views. When you redirect router.navigate("articles", true);
the view itself is not destroyed and it continues to wait for the element to be clicked. In fact, it just hangs in memory, and when you render a new view in the same place, the previous ones catch a click on #submit_edit_article
.
In short: destroy views if you are not using them.
For a better understanding, put a breakpoint in the method edit
and look at the callstack from where the call comes from and on which object it is caught. cid
the views will be different.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question