我正在使用主干、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。但是,这似乎是个坏主意。任何人都可以建议我使用主干和科尔多瓦构建单页应用程序的任何起始示例吗?