I tried a few combinations, but I am stuck. Any help is appreciated. How do I read the JSON record here please (is the syntax for the JSON organised well?) I keep getting TypeError: Cannot read property '0' of undefined with the code below and or permutations of it.
JSON:
{
"wty_upgrade":[{
"wty":"Upgrade from 3 to 5 years",
"mth":24,
"pig":3000
},
{
"wty":"Upgrade from 3 to 10 years",
"mth":84,
"pig":8000
}]
}
CODE:
function LoadWtyUpgPlans(wty) {
var WtyRow = '';
var WtyYears = '';
for (var i = 0; i < wty.wty_upgrade[0].length; i++) {
WtyYears = wty.wty_upgrade[0].mth[i] / 12;
WtyRow +='<tr> \
<td> \
<input type="hidden" class="smg-wty-up-val" value="' + wty.wty_upgrade[0].mth[i] + '"> \
' + wty.wty_upgrade[0].wty[i] + ' \
</td> \
<td align="right">' + WtyYears + '</td> \
<td align="right">' + wty.wty_upgrade[0].pig[i] + '</td> \
</tr>';
};
};
wty.wty_upgrade[0].lengthconsole.log(wty)to see what's in there - where is it failing? I'm going to assume it'swty.wty_upgrade[0].mth[0]here - try justwty.wty_upgrade[0].mth