我正在尝试使用 windows.history.back() 但没有任何反应。恰好当事件调用 history.back 出现几秒钟或更短的时间时,只会出现前一页的菜单。
在调用函数的视图下方:
var LandscapeView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
},
initialize: function() {
this.geolocation();
$(window).on('orientationchange', this.onOrientationChange);
},
/* render: function() {
//var context = JSON.parse(JSON.stringify(this.model));//eliminare
//var context=this.model;
var html =this.template();
this.$el.html(html);
$('#pagina').empty();
$('#pagina').append(this.$el.html(html));
return this;
},*/
geolocation:function(){
navigator.geolocation.getCurrentPosition(win);
function win(pos){
console.log("gps");
/* var el='<div>'+ pos.coords.latitude+'</div>';
el+='<div>'+ pos.coords.longitude+'</div>';
el+='<div>'+ pos.timestamp+'</div>';
$('#pagina').html(el);*/
var lat=pos.coords.latitude;
var lon=pos.coords.longitude;
var options={
center:new google.maps.LatLng(lat,lon),
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var html=$('#pagina');
console.log(html);
var map= new google.maps.Map(document.getElementById('pagina'),options);
console.log(map);
};
},
onOrientationChange: function() {
if(window.orientation === 0) {
window.history.back();
}
}
});
return LandscapeView;
});
在这里,history.back 无法重新调用之前的视图:
var HomeView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
"click .log_out":"log_out",
"click .prove":"prove",
},
initialize: function() {
console.log("inhomeview");
this.render();
$(window).on('orientationchange', this.onOrientationChange);
},
render: function() {
//var context = JSON.parse(JSON.stringify(this.model));//eliminare
var context=this.model;
var html =this.template(context);
console.log(html);
this.$el.html(html);
$('#pagina').empty();
$('#pagina').append(this.$el.html(html));
return this;
},
onOrientationChange: function() {
if(window.orientation === 90 || window.orientation === -90) {
new LandscapeView();
}
},
log_out:function(){
console.log("logout");
Parse.User.logOut();
// new AppView;//ERRORE UNDEFINED NOT A FUNCTION
window.location='index.html' ;//METTERE UNA NEW APPVIEW MA DA ERRORE!!!
},
prove:function(){
navigator.geolocation.getCurrentPosition(win);
function win(pos){
console.log("gps");
/* var el='<div>'+ pos.coords.latitude+'</div>';
el+='<div>'+ pos.coords.longitude+'</div>';
el+='<div>'+ pos.timestamp+'</div>';
$('#pagina').html(el);*/
var lat=pos.coords.latitude;
var lon=pos.coords.longitude;
var options={
center:new google.maps.LatLng(lat,lon),
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var html=$('#pagina');
console.log(html);
var map= new google.maps.Map(document.getElementById('pagina'),options);
console.log(map);
};
}
});
return HomeView;
});
这是我的路由器:
var AppRouter = Backbone.Router.extend({
routes: {
"": "home",
"user/:objectId":"prova",
"settings":"settings",//mettere id dell utente loggato
"friends":"friends",
"mailbox":"mailbox"
},
home: function() {
console.log("inrouter");
new AppView();
},
settings: function(){
console.log("settings");
var view=new SettingsView();
$('#pagina').html(view.render().el);
},
friends: function(){
console.log("friends");
var view=new FriendsView();
$('#pagina').html(view.render().el);
} ,
mailbox: function(){
console.log("mailbox");
}
});
return AppRouter;
});
这里是历史开始的主要地方:
document.addEventListener("deviceready", run, false);
run();
function run() {
var sync = Backbone.sync;
Backbone.sync = function(method, model, options) {
options.beforeSend = function (xhr) {
xhr.setRequestHeader('X-Parse-Application-Id', 'qS0KLMx5h9lFLG**yhM9EEPiTS3VMk');
xhr.setRequestHeader('X-Parse-REST-API-Key', 'nh3eoUo9G**vbF2gMhcKJIfIt1Gm');
};
sync(method, model, options);
},
app = new AppRouter();
Backbone.history.start();
Parse.$ = jQuery;
Parse.initialize("qS0KLMx5h9l****tyhM9EEPiTS3VMk",
"H4m*****aGOBqlWzRDW8IrPDpF9qLN7Duy");
}