I'm using json2html.js to parse json data into html, I have come into a problem when trying access a child's array parent property, I know it may not be possible but may be you can enlighten me on how to do it, the below example is the JSON string and json2html transformation...
{ "date": "2013-11-18", "cityid": "2", "timeframe": "2", "timeslots": [{ "time": "07:00:00", "avail": 1 }, { "time": "17:00:00", "avail": 0 }] }
We use 2 different transformation strings 1 to render the top part(date, cityid,timeframe) and another to render the inner part (timeslots) the problem is that we need to access data from he top part such as timeframe property or object array index from the timeslots array transformation below are the two transformations we use to render:
var stimes = {
"tag": "li",
"children": [{
"tag": "input",
"type": "radio",
"id": function (obj, index) {
return (index);
},
"value": "${time}",
"name": "btn",
"html": ""
}, {
"tag": "label",
"for": "0_1",
"html": function (obj) {
return (fixFrame(obj.time, 2));
}
}]
};
var daysheader = {
"tag": "div",
"id": function (obj, index) {
return ("day_" + index)
},
"class": "daycol",
"children": [{
"tag": "ul",
"children": [{
"tag": "li",
"children": [{
"tag": "h3",
"html": function (obj) {
return (formatDay(obj.date, "dddd"))
}
}, {
"tag": "p",
"class": "dat",
"html": function (obj) {
return (formatDay(obj.date, "mmm dS"))
}
}]
}, {
tag: "p",
children: function (obj) {
return (json2html.transform(obj.timeslots, stimes));
}
}]
}]
};
We also need the parent array index to generate different id's for each radio input, here is a link to the test... http://jsfiddle.net/viktorq/wRT74/