Created
April 16, 2012 16:27
-
-
Save OndeVai/2399789 to your computer and use it in GitHub Desktop.
KnockoutJS Make Json Data Observable (lighter mapping plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//todo make this a plugin for ko | |
function makeAllPropsObservable(jsonData) { | |
////console.log(jsonData.DivisionSummaries); | |
for (x in jsonData) { | |
////console.log(x + ' ' + jsonData[x]); | |
if (!$.isFunction(jsonData[x])) { | |
if (!$.isArray(jsonData[x])) { | |
if (!$.isPlainObject(jsonData[x])) | |
jsonData[x] = ko.observable(jsonData[x]); | |
else { | |
var plainObj = jsonData[x]; | |
makeAllPropsObservable(plainObj); | |
} | |
////console.log(x + ' ' + jsonData[x]()); | |
} | |
else { | |
jsonData[x] = ko.observableArray(jsonData[x]); | |
var arr = jsonData[x]; | |
for (var i = 0; i < arr().length; i++) { | |
makeAllPropsObservable(arr[i]); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment