Knockout.js Make every nested object an Observable

I would use the knockout mapping plugin. var jsonData = { id : 1, details: { name: “Johnny”, surname: “Boy” } } var yourMapping = { ‘details’: { create: function(options) { return Details(options.data); } } } function Details(data) { ko.mapping.fromJS(data, {}, this); } function YourObjectName() { ko.mapping.fromJS(jsonData, yourMapping, this); } This will create your object … 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

Performance tuning a knockout application – guidelines for improving response times

I think that it would be too much to layout the tips that I have in mind in one answer. I started a series of blog posts on this topic. The first post is here. This post describes a bit how if/with work (copies the children as its template and re-renders using the template whenever … Read more

Am I overusing the Knockout mapping plugin by always using it to do my viewmodel?

After using Knockout for a little longer, I’ve noticed that the mapping plugin has some additional options that give you much more fine grained control over the mapping process. Control type and amount of properties generated There are several ways to accomplish this, and I’ll go over some, but the end result is that you … Read more

Binding true / false to radio buttons in Knockout JS

I know this is an old thread, but I was having the same problem and found out a much better solution that was probably added to knockout after this question was officially answered, so I’ll just leave it for people with the same problem. Currently there is no need for extenders, custom binding handlers or … 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.

tech