如何编写从纵向切换到横向的事件?如何在浏览器调试中进行此切换?这是必须捕获事件横向的 View 。也许在对象事件中?或者你可以建议我吗?
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();
},
render: function() {
//var context = JSON.parse(JSON.stringify(this.model));//eliminare
var context=this.model;
var html =this.template(context);
console.log(html);
$('#pagina').empty();
$('#pagina').append(this.$el.html(html));
return this;
},
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(){
var lista=new Usercollection();
lista.fetch();
console.log(lista.length);
}
});
return HomeView;
});
最佳答案
我猜您一定为 view
对象指定了 el
。
您在事件哈希
中指定的所有事件都将委托(delegate)给该view
对象的el
。
所以你可以这样写来监听 orientationchange
事件。
events: {
'orientationchange' : 'onOrientationChange'
}
onOrientationChange: function() {
if(window.orientation == 90 || window.orientation == -90) {
//you are in landscape zone
//do whatever you want to do
}
}
关于javascript - 如何让事件在backbone中从纵向切换到横向?以及如何在浏览器调试中切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16501014/