I'm using revealing module pattern and knockout js file contains viewmodel something like this
// The ViewModel
var viewmodel = function (){
model = ko.mapping.fromJS([]),
init = function(initialData) {
model = initialData;
},
save = function(data, event) {
$.ajax({
// ....
});
},
delete = function(data, event) {
$.ajax({
// ....
});
};
return{
Init : init,
Save : save,
Delete : delete
};
};
view contains script to initialize viewModel and bindings
$(document).ready(function () {
viewmodel.Init(Model.toJSON());
ko.applyBindings(viewmodel);
});
Not sure if it's the best way but it works.
- Regards -
J O N