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.
JsFiddle
You can convert it back to JavaScript object like this :