javascript - 事件方向更改在主干中不起作用

标签 javascript backbone.js

通过主干中的上述事件,我无法检测方向。它不起作用。有没有其他选择?通过绑定(bind)事件或其他东西?或者我的代码中有问题?

var HomeView = Backbone.View.extend({
    template: Handlebars.compile(template),
    events: {
        "click .log_out": "log_out",
        "click .prove": "prove",
        "orientationchange": "onOrientationChange"
    },

    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;
    },

    onOrientationChange: function () {
        if (window.orientation === 90 || window.orientation === -90) {
            alert('you are in landscape');
        }
    }
});

最佳答案

仅当您将 view el 设置为 window 时,它才有效。

或者您可以手动订阅orientationchange事件:

initialize : function() {
    $(window).on('orientationchange', this.onOrientationChange);
}

关于javascript - 事件方向更改在主干中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16511112/

相关文章:

javascript - 工具提示方向 mozilla

javascript - 两次按键不同功能运行

javascript - 为什么 backbone 不使用 module.exports?

javascript - GET 方法返回 500 内部服务器错误

javascript - 在 TypeScript 中调用 NPM 模块的 JS 函数

javascript - 如何在 marionette 中渲染没有 model.toJSON() 的模板

javascript - this.$el 和 jQuery

javascript - 使用 Backbone.js w/Require.js 的站点在 IE8 中的错误

json - underscore.js - 对象不支持此属性或方法 - ie8

javascript - 如何在 Angular 中设置 DfxParser