バックボーンjsのView.remove()関数は、ビュー自体のコンテナ要素をDOMから削除して、削除されたビューを再作成しないようにします。最後の2行は、上記のid =「attrsに」とdiv要素としてビューを再作成していないバックボーンで削除されたビューを再作成するjs
var AttributeView = Backbone.View.extend({
el: $("#attrs"),
template:_.template($('#attrs-template').html()),
initialize:function() {
},
render:function (eventName) {
$(this.el).html(this.template(this.model.toJSON()));
return this;
},
dispose:function(eventName){
this.unbind();
this.remove();
},
});
var attrView = new AttributeView();
....
attrView.dispose();
//Later on some event I do the below
attrView = new AttributeView()
attrView.render();
このシナリオでは、ここで
私のコードがある
の処理方法任意のアイデアは、もはやありません。
ご返信ありがとうございます。しかし、何らかの理由であなたの例に似たコードが動作しません。私はhttp://jsfiddle.net/EnVmN/7/を作成して、私が持っている問題を説明しました。私が間違って何をしているのか。私はあなたのAttributeViewを再利用していますが、ItemViewを追加して、それぞれのアイコンの編集と削除をクリックするとattributeviewを表示して削除しようとしています。 – mzafer
@mzafer:ビューのイベントはビューの 'el'とその子のみで動作しますが、ItemViewは'#items'にレンダリングされましたが、ItemViewの 'el'ではなく、アイコン上のクリックイベントはItemView:http://jsfiddle.net/ambiguous/KjC6x/ –
ありがとう、それは今働いています:)これで約2日を費やしました。 – mzafer