I have a basic view that is responsible for displaying other views .... Here's the full code (1) (2) (3).
When I load the views for the first time (View1, View2, View3), everything is fine.
Then, if I try to reload the view by changing this. Obviously, this seems to be normal ..
But I noticed that there are some zombie looks ...,
I mean an example of previous representations in memory.
I discover this using this world of code ...
View1 = Backbone.View.extend({ initialize: function () { this.model.on('change', function () { console.log(this.cid); }, this); } });
Looking at cid
, I found that every time I reload a new view view with different cid generated and remain in memory. Exam
** first load **: console.log(this.cid); // cid:12 ** Second load ** console.log(this.cid); // cid:12 console.log(this.cid); // cid:13
Etc...
What is wrong with my design? how can i fix this?
(1) entry point
require([ "js/mainApp" ], function(App){ App.initialize(data.id); });
(2) mainApp
define([ "js/views/taskDetailView" ], function (TaskDetailView) { var initialize = function(task_id){ var vent; vent = _.extend({}, Backbone.Events);
(3)
define([ "js/views/view1", "js/views/view2", "js/views/view3", "text!templates/Task/TaskDetailedView.html" ], function (View1, View2, View3, taskDetailedViewTemplate) { var TaskDetailView = Backbone.View.extend({ el: $(".project-content"), initialize: function () { this.render(); }, render: function () { var options; // render from template and assign this.el to the root of the element // eg .project-content this.setElement($(Mustache.render(taskDetailedViewTemplate))); this.view1 = new View1(_.extend( {el:this.$("#taskView")} , this.options)); this.view2 = new View2(_.extend( {el:this.$("#feedView")} , this.options)); this.view3 = new View3(_.extend( {el:this.$("#followerView")} , this.options)); } }); return TaskDetailView; });