I have
$.getJSON('json.ashx?mode=Gender', function (data) {
memberInfo = data[1];
options.series = data;
originalData = data[0];
...
...
});
which returns
[
{"type" : "pie","name" : "Gender",
"data" : [["Male",32],["Female",11]]},
{"A123":"F","A223":"M","A423":"F","A332":"M","B327":"F"}
]
and
function calcOptionsData() {
...
var maleCount = 0;
var femaleCount = 0;
...
...
$.each(val, function(index, item) {
if (memberInfo[item] == 'M')
maleCount += 1;
if (memberInfo[item] == 'F')
femaleCount += 1;
});
options.series[0].data[0][1] = originalData.data[0][1];
options.series[0].data[1][1] = originalData.data[1][1];
if (radioBttnClicked == 'Gender')
{
options.series[0].data[0][1] += maleCount;
options.series[0].data[1][1] += femaleCount;
}
}
I want every times the calcOptionsData() called the originalData resets the options.series[0].data to the value originally generated from the getJSON. The current code mirrors originalData with options.series[0].data.
Thanks,
You may use
$.extend(true, {}, originalObject)to create an independent deep copy of a JSON object.Then you may use this copy for any purpose without affecting the original object.
See the docs for more information.