Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any knockoutjs page/routing frameworks?

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's really cool that webapi's can be run independent of IIS!

That being said:

Are there any page frameworks that can leverage KnockoutJS which are similar to my mock-up below:

Framework.RegisterRoutes(..,mainViewModel);//sets the CurrentViewModel? 

Each route being a separate file of a viewModel, and a view to be injected into the master view

var mainviewModel= function(){    var self = this;    self.CurrentViewModel = ko.observable();    ...    return self; }  <div id="mainPageContent" data-bind:'html:CurrentViewModel.Render'> </div> 

I know that a lot of this can be achieved by self, but not sure how to achieve the register routes/ loading separate files

I feel like knockoutjs's main strengths is the ability to not intrude into the way you code js (ie build an object/framework how you want so long as the interacting objects are observable)

like image 519
maxfridbe Avatar asked Mar 14 '12 15:03

maxfridbe


People also ask

Is knockout a library or framework?

Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.

Is knockout still used?

KnockoutJS is far from dead, and it's actually still being improved and evolved (see Technical Knockout) but newer frameworks seem a far better bet for our needs, considering activity and performance.

What is KnockoutJS used for?

KnockoutJS is basically a library written in JavaScript, based on MVVM pattern that helps developers build rich and responsive websites.

What is KnockoutJS in asp net?

Knockout. Js (simply KO) is a powerful JavaScript library which allows developers to bind DOM elements with any data model like array, Json etc.


2 Answers

Pager.js is a URL routing framework built specifically for use with Knockout.js. Make sure you go through the entire Demo to see its full power and flexibility. IMHO, it far exceeds PathJS and Sammy.

like image 149
James Messinger Avatar answered Oct 14 '22 18:10

James Messinger


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.

like image 44
John Papa Avatar answered Oct 14 '22 16:10

John Papa