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

Setting value of Observable not updating in Knockout

Setting value of Knockout Observable / Observable Array doesn’t update You need to use the setter function to update the value of your observable / observableArray – Ex. 1 (observable) – var name=”John”; var myValue = ko.observable(); myValue(name); // Set myValue equal to John, update any subscribers var newObservable = ko.observable(‘Bill’); myValue(newObservable()); // Set myValue … Read more

knockoutjs databind with jquery-ui datepicker

You could write a custom binding that sets the date in the field using the datepicker APIs and also sets the value of your observable by reading the date properly. The custom binding might look like: ko.bindingHandlers.datepicker = { init: function(element, valueAccessor, allBindingsAccessor) { var options = allBindingsAccessor().datepickerOptions || {}, $el = $(element); //initialize datepicker … Read more

Example of knockoutjs pattern for multi-view applications [closed]

There are a few directions that you could go with this one. One option is to call ko.applyBindings with distinct view models against separate DOM elements like: var viewModelA = { name: “Bob” }; var viewModelB = { price: 50 }; ko.applyBindings(viewModelA, document.getElementById(“aContainer”)); ko.applyBindings(viewModelB, document.getElementById(“bContainer”)); http://jsfiddle.net/9abgxn8k/ In this case, you would want to make sure … Read more