0

ons-sliding-menu当用户按下android的后退按钮时,我想关闭。我怎样才能做到这一点?目前的实现是:

    var manager = {
        initialize: function() {
            this.bindEvents();
        },
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },
        onDeviceReady: function(){
            document.addEventListener("backbutton", manager.onBackKeyDown, false);
            document.addEventListener("menubutton", manager.onMenuKeyDown, false);
        },
        onBackKeyDown: function(){
            // close ons-sliding-menu if opened
        },
        onMenuKeyDown: function(){
            // close or open ons-sliding-menu
        }
    };
    
    manager.initialize();

我试过打电话ons.slidingMenu.toggleMenu(),但是ons当事件触发undefined时。onBackKeyDown

4

2 回答 2

1

the OnsenuUi 1.1.x has the component ons-back-button

于 2014-08-02T03:04:42.937 回答
0

这可能通过在事件上使用事件侦听器来实现$routeChangeStart。像这样的事情应该这样做。

$rootScope.$on('$routeChangeStart', function () {
  // I'd probably rename this function no to something like closeMenuIfOpen??
  manager.onBackKeyDown();
});
于 2014-07-04T21:50:23.460 回答