1
jumpToWave事件只會觸發一次,我不明白爲什麼。Backbone.View事件只會觸發一次
這是我的看法:
var WaveModalView = Backbone.View.extend({
template:_.template($('#tpl-wave-modal').html()),
events: {
'hidden': 'remove',
'click .jumpToWaveBtn':'jumpToWave'
},
jumpToWave:function(e){
e.preventDefault();
console.log("JMP")
var marker = this.model.collection.markers[this.model.id];
map.panTo(marker.getPosition());
bounceMarker(marker,1750);
},
render:function() {
var model = this.model;
var that = this;
$(this.el).html(this.template(model.toJSON()));
if(model.get('waveReviews').length > 0){
var reviewList = new WaveReviewList({model: model});
$('#waveReviews' + model.id).html(reviewList.render().el);
}
this.$("#waveSync" + model.id).click(function(e){
e.preventDefault();
if(window.me){
requestSyncWave(model.id,function(data){
window.me.fetch();
});
}
});
this.$("#waveEdit" + model.id).click(function(e){
e.preventDefault();
window.waveUnderEdit = model;
$(that.el).children(":first").modal('hide');
openWaveEditModal(model);
});
return this;
}
});
這是在模板中的相關按鈕:
<button class="btn btn-info jumpToWaveBtn" data-dismiss="modal" aria-hidden="true">Auf Karte
anzeigen</button>
我有時間多模態我按一下按鈕。這個事件在每一個模式中被觸發一次,之後「JMP」不再被記錄。
是做到了,謝謝你。你可以詳細介紹一下delegateEvents嗎? – MJB 2013-03-11 13:43:57
你是否檢查過'delegateEvents()'的官方文檔? http://backbonejs.org/#View-delegateEvents – 2013-03-11 17:14:09