I am currently working with JSON data that looks like this:
{"orders":[
{"id":16,"status":"completed","total":"45.00"},
{"id":17,"status":"completed","total":"55.00"}
]}
My goal is to convert this data into HTML using json2html. While ${orders.0.total}
works for the first array item, I want it to transform all orders, not just the one at index 0.
I attempted a solution found in this answer, but unfortunately, it did not work as expected.
This is what my current implementation looks like:
<body>
<ul id="list"></ul>
</body>
<script type="text/javascript">
//List items
var myjson = [{"data":[
{"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>
Thank you.