开发者

Backbone.js unable to access the router functions?

开发者 https://www.devze.com 2023-04-05 04:08 出处:网络
I have a simple implementation of Backbone.js which goes like this - $(document).ready(function(){ Workspace = Backbone.Router.extend({

I have a simple implementation of Backbone.js which goes like this -

$(document).ready(function(){
    Workspace = Backbone.Router.extend({
    routes: {
    "/getAcademics": "academics"
        }, 

    academics: function(){
            alert("ok");
    $("#content").append("<div>Academics</div>");
    }
    }); 
var myWorkspace = new Workspace;
});

The link in the body is given开发者_StackOverflow社区 as -

     <a href="#/getAcademics">Academics</a>

Though the router routes to the link #/getAcademics but it does not execute the function academics. Any clues as how to rectify this. Am I missing something else.

Thanks


After you instantiate your router, and before you attempt to use any of its routes, you need to call Backbone.history.start(). This will setup a listener for hash changes and call the correct route functions when needed.

You can find more information here: http://documentcloud.github.com/backbone/#History

0

精彩评论

暂无评论...
验证码 换一张
取 消