I have the following JSON data:
{"orders":[
{"id":16,"status":"completed","total":"45.00"},
{"id":17,"status":"completed","total":"55.00"}
]}
how do I transform this data to html using json2html?
${orders.0.total}
works but I want it to transform all orders, not just array 0.
I have tried the solution from this answer, but it won't work.
This is what I have:
<body>
<ul id="list"></ul>
</body>
<script type="text/javascript">
//List items
var myjson = [{"orders":[
{"id":16,"status":"completed","total":"45.00"},
{"id":17,"status":"completed","total":"55.00"}
]}];
//List item transform
var orderTransform = {"tag":"div","html":"${total}"}
var transform = {"tag":"div","children":function(){
return( json2html.transform(this,orderTransform) );
}};
$(function(){
//Create the list
$('#list').json2html(myjson,transform);
});
</script>
thx