0

我正在使用主干、jquery 和 cordova 2.7.0 构建单页应用程序。

我的起始页看起来像这样

 <div id="activity-container">
     <form action="/login" id="login-form" onsubmit="return false;">
        <input id="username" type="text"/>
        <input id="password" type="password"/>
        <a href="#login">Sign In</strong></a>
    </form>
 </div>

我写loginview如下

 LoginView = Backbone.View.extend({
    el: $("#login-form"),
    events: {
        "click #login": "authenticate"
    },
    authenticate: function(){
        new SecondView();
    }
});

secondview 只需要 someTemplate 并在 id="acitivity-container" 的 div 中渲染。我把它写成

   SecondView = Backbone.View.extend({
    el:$("#activity-container"),
    template: _.template( $("#someTemplate").html() ),
    initialize: function () {
        this.$el.html( this.template 
    },
    render: function () {           
        this.$el.html( this.template );
        return this;
    }
  });

我只是想检查一下。所以,我的模板现在是任何静态 html。前任

   <script type="text/someTemplate">
      <p>Anything here<p>
   </script>

我使用以下代码初始化应用程序

 document.addEventListener('deviceready', onDeviceReady, false);
     function onDeviceReady() {
            new loginView();
            Backbone.history.start();
     }

这工作正常。当我单击登录时,它会将我带到约会视图。现在,当我在键盘上按“ESC”时,这将使我退出应用程序,而不是返回登录视图。这只是意味着我不能回去。我们如何解决这个问题?

我的想法是我将构建每个视图并将它们连接到“活动容器”div。但是,这似乎是个坏主意。任何人都可以建议我使用主干和科尔多瓦构建单页应用程序的任何起始示例吗?

4

1 回答 1

0

不确定使用cordova与在网络浏览器上的操作有何不同,但我建议您在文档中查看路由器和历史记录。

http://backbonejs.org/#Router

http://backbonejs.org/#History-start

也看看这个问题,可能是一个类似的问题:

Backbone.history.start() 阻止后退按钮离开页面

你也可以看看 window.history.back()

我想我不清楚的唯一其他可能性是,如果您只是试图覆盖 Cordova 如何处理 Esc 键。

于 2013-05-28T15:49:17.163 回答