Knockout JS mapping plugin without initial data / empty form

A couple of options for you besides just manually managing your view model. The mapping plugin supports a create callback that lets you customize how it gets created. This can be used to add default properties to an object, if they happen to be missing. Something like this: http://jsfiddle.net/rniemeyer/WQGVC/ Another alternative is to use a … Read more

Map JSON data to Knockout observableArray with specific view model type

Check this http://jsfiddle.net/pTEbA/268/ Object.prototype.getName = function() { var funcNameRegex = /function (.{1,})\(/; var results = (funcNameRegex).exec((this).constructor.toString()); return (results && results.length > 1) ? results[1] : “”; }; function StateViewModel(data){ this.name = ko.observable(); ko.mapping.fromJS(data, mapping, this); } function CityViewModel(data) { this.name = ko.observable(); ko.mapping.fromJS(data, mapping, this); } function StreetViewModel(data) { this.name = ko.observable(); ko.mapping.fromJS(data, mapping, this); … Read more

KnockOutJS – Multiple ViewModels in a single View

Knockout now supports multiple model binding. The ko.applyBindings() method takes an optional parameter – the element and its descendants to which the binding will be activated. For example: ko.applyBindings(myViewModel, document.getElementById(‘someElementId’)) This restricts the activation to the element with ID someElementId and its descendants. See documentation for more details.