view.remove() を呼び出すたびに、dom からビューを削除するだけでなく、ボディ全体も削除するように見えます
各ビューの作成後に showView を呼び出しています
showView : function(view) {
if (this.currentView) {
this.currentView.remove();
this.currentView.unbind();
if (this.currentView.onClose) {
this.currentView.onClose();
}
}
this.currentView = view;
$('body').html(this.currentView.render().el);
}
body 要素がなくなったため、別のビューを追加できません
Chrome デバッガー出力:
$('html')
<html>
<script id="tinyhippos-injected">…</script>
<head>…</head>
</html>
view.remove() が実行されると、画面が白くなり、 $('body').html(this.currentView.render().el); に再入力されません。
編集:
各ビューを el: $('.body') から el: '.mainContent' に変更し、index.html ファイルに a を追加しました。
app.showView で、mainContent div が削除されている場合は追加します。ボディ全体よりも div を削除することをお勧めします。
if($('.mainContent').length == 0)
$('body').append('<div class="mainContent"></div>');
解決:
ビューの削除メソッドをオーバーライドする必要がありました。el 全体を削除したくはありませんでした。コンテンツだけを削除したかったのです:バックボーン js で削除されたビューを再作成する
Backbone.View.prototype.remove = function() {
this.undelegateEvents();
this.$el.empty();
return this;
};