I have javascript array in this format:
omega.franchiseInfo.rawdata = [{
Id: "Main",
Title: "Main",
Type: "main",
items: [{
Id: "Menu1",
Title: "Menu1",
Type: "menu",
items: [{
Id: "Menu1",
Title: "Menu1",
Type: "menu",
items: []
}]
}]
}];
Every item has a property items which is an array containing other items. The number of elements of the array is not specified.
I am using the knockout mapping plugin on the array to make it observableArray. And all the members of the array also become observables.
omega.franchiseInfo.observableRawData = ko.mapping.fromJS(language.rawdata);
What I want to accomplish is then unwrap the omega.franchiseInfo.observableRawData
to become in its original pure javascript format. That means to be equal to omega.franchiseInfo.rawdata
. I know that there are methods in knockout like ko.utils.unwrapObservable
but javascript is not my strong side and I couldn't make it work for my case. Also I think that the function that will do the job should be recursive to go through all the items in the array.
Here is my fiddle:
http://jsfiddle.net/KHFn8/931/
I will be very greatfull if somebody can help me with that and provide a working code. Thank You for your time and effort.
An observableArray just tracks which objects it holds, and notifies listeners when objects are added or removed.
ko. utils were built to support the internals of Knockout, so that it is able to have no strict dependencies. The utility functions generally do similar things that can do with libraries like jQuery and Underscore.
ObservableArray is an array that allows listeners to track changes when they occur.
JsFiddle
You can convert it back to JavaScript object like this :
ko.toJS(omega.franchiseInfo.observableRawData);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With