我正在使用requirejs和主干开发一个应用程序,在索引视图(索引页面)中我遇到了2个困难......
当我使用这样的导航功能时:
this.navigate("dashBoard/");
它不起作用,以防我使用:
Backbone.history.navigate("dashBoard/");
它工作正常。即使在我的“路线”中我没有触发该功能。这是我的索引视图..
define(["singleton","backbone"],function (obj,Backbone) {
window.EDMS = obj || {};
EDMS.index = Backbone.View.extend({
el:$(".loginPage > section"),
events:{
"click #loginBtn" : "enter"
},
initialize:function(){
this.$el.html(this.template());
},
enter:function(e){
e.preventDefault();
var userName = $.trim(this.$el.find("#userName").val()),
password = $.trim(this.$el.find("#password").val());
if(userName && password){
Backbone.history.navigate("dashBoard/"); //only this is works
//this.navigate("dashBoard/") not working.
}else{
return false;
}
}
});
return EDMS.index;
})
但是在“EDMS.routers”控制台的情况下 - 我正在获取方法......如何将我的索引视图正确同步到路由器......有什么帮助吗?
我的 routers.js
define(["singleton","backbone","utils"], function (EDMS,Backbone,utils) {
window.EDMS = window.EDMS || {};
EDMS.routers = Backbone.Router.extend({
routes:{
"":"caller",
"dashBoard/":"dashBoard"
},
initialize:function(){
utils(["index"]);
},
caller:function(){
console.log("i am called");
},
dashBoard:function(){
console.log("welcome to dashBoard");
}
});
return EDMS.routers;
})
我的应用在 require.js 上初始化
require(["jquery","underscore","backbone","singleton","routers"],function ($,_,Backbone,EDMS,routers) {
EDMS.router = new EDMS.routers();
Backbone.history.start();
});