他のビューのレンダリングを担当するメインビューがあります…。これが完全なコードです(1)(2)(3)。
ビュー(View1、View2、View3)を初めてロードするときは、すべて問題ありません。
次に、this.optionsを変更してビューをリロードしようとすると、どうやら問題ないようです。
しかし、ゾンビビューがいくつかあることに気付きました…、つまり
、メモリ内の以前のビューのインスタンスを意味します。
私はこのコードの平和を使用してこれを発見します…</p>
View1 = Backbone.View.extend({
initialize: function ()
{
this.model.on('change', function () {
console.log(this.cid);
}, this);
}
});
cid
ビューを再ロードするたびに、異なるCIDを持つ新しいビューが生成され、メモリにとどまることがわかりました。例
** first load **:
console.log(this.cid); // cid:12
** Second load **
console.log(this.cid); // cid:12
console.log(this.cid); // cid:13
等々...
私のデザインの何が問題になっていますか?どうすれば修正できますか?
(1)エントリポイント
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); // The Event Aggregator
var taskDetailView = new TaskDetailView({
task_id: task_id,
vent: vent
});
$(".project-content").html(taskDetailView.$el);
}
return {
initialize: initialize
};
});
(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
// e.g .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;
});