Re:Backbone vs Knockout
by IanDrake on Tuesday November 22, 2011 @10:33AM
(#3265857)
I've used knockoutjs on a few projects now and I think I could help, but the article is down, so I don't understand the context of your question.
There are several way to structure your app, but it depends on what your app does and how structured it is. On a basic level I structure every page to have a page object to handle events and setup the view model(s).
So, for default.aspx, I might have something like:
var Page = new function(){
_this = this;
$(function(){
//document ready
});
$("#dataTable").delegate(".delete",function(){
_this.viewModel.deleteItem(ko.dataFor(this));
});
this.viewModel = new function(){
var _this = this;
//set up view model
this.observableVal = ko.observable("");
this.deleteItem = function(){
//delete item from VM
};
};
};
But then you might want to have a page with multiple view models (ie UserControls that are self contained). This gets a bit tricky, especially if you want the multiple view models to interact.
There are several way to structure your app, but it depends on what your app does and how structured it is. On a basic level I structure every page to have a page object to handle events and setup the view model(s).
So, for default.aspx, I might have something like:
var Page = new function(){ _this = this;
};But then you might want to have a page with multiple view models (ie UserControls that are self contained). This gets a bit tricky, especially if you want the multiple view models to interact.
Shoot me an email if you need help.