3

インデックス ビュー (インデックス ページ) で、requirejs とバックボーンを使用してアプリケーションを開発しています。2 つの問題が発生しています...

  1. 次のようにナビゲート機能を使用すると:

    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();
});
4

1 に答える 1