Are there any knockoutjs page/routing frameworks?

前端 未结 6 649
时光取名叫无心
时光取名叫无心 2020-12-23 02:13

Coming from asp.net MVC 3. In MVC4 they introduced WebAPI\'s. It would be nice to be able to do all view/routes code in javascript and just rely on MVC for API. Heck it\'

6条回答
  •  清歌不尽
    2020-12-23 02:57

    Sammy.js is an excellent lightweight routing JavaScript library. You can do things like this to route when used in pair with Knockout (from the tutorials web site or KnockoutJS):

    $.sammy(function() {
        this.get('#:folder', function() {
            self.chosenFolderId(this.params.folder);
            self.chosenMailData(null);
            $.get("/mail", { folder: this.params.folder }, self.chosenFolderData);
        });
    
        this.get('#:folder/:mailId', function() {
            self.chosenFolderId(this.params.folder);
            self.chosenFolderData(null);
            $.get("/mail", { mailId: this.params.mailId }, self.chosenMailData);
        });
    
        this.get('', function() {
            this.app.runRoute('get', '#Inbox');
        });
    }).run();  
    

    Another option is to use SproutCore, but its so much more than nav, so I dont recommend that route unless you want all of SproutCore. There are plenty of other libraries, but I like Sammy.js so far due to how lightweight it is.

提交回复
热议问题