我想調用當前視圖的功能deleteMarker
,點擊瀏覽器的後退按鈕。我搜索了類似的問題,但沒有人能幫助我。骨幹:點擊瀏覽器後退按鈕時調用視圖的功能
目前認爲我想調用函數deleteMarker
後退按鈕被點擊時:
ev.views.Evento = Backbone.View.extend({
map: 'null',
initialize: function(id){
.....
},
// function that will call
deleteMarker: function(){
this.marker.remove();
},
render: function(id){
.....
}
});
app.js
var ev = new Application();
ev.Router = Backbone.Router.extend({
routes: {
"": "home",
"evento/:id" : "evento"
},
home: function(){
setTimeout(function(){
$('#rightcolumn').html(new ev.views.Home_Eventos(ev.shell.map).el);
}, 0);
},
evento: function(id){
$('#rightcolumn').html(new ev.views.Evento(id).el);
}
});
$(document).on('ready', function() {
ev.templateLoader.load(['shell', 'home_list_eventos', 'evento'], function() {
ev.shell = new ev.views.Shell({el: "#shell"});
ev.router = new ev.Router();
Backbone.history.start();
});
});
在ev.Router.home中,爲什麼要用毫秒參數0調用'setTimeout'?在我看來,這打破了'setTimeout'的觀點。 – 76484
我搜索了一下這個模式的一些有趣的討論:http://stackoverflow.com/questions/779379/why-is-settimeoutfn-0-sometimes-useful – 76484
http://stackoverflow.com/questions/14543245/browser-後退按鈕處理http://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser只需在'Router'中監聽事件並觸發Backbone事件,該觀點可能正在傾聽做它的工作。 –