0
/wの配列にJSONデータのインライン関数を作成します。json2html - 私は次のようなJSONデータを持っている複数の要素
{"orders":[
{"id":16,"status":"completed","total":"45.00"},
{"id":17,"status":"completed","total":"55.00"}
]}
どのように私はjson2htmlを使用してHTMLにこのデータを変換しますか? ${orders.0.total}
作品が、私はそれがすべての注文を変換したいだけではなく、配列0
私はthis answerから解決策を試してみましたが、それは動作しません。
これは私が持っているものです:ルートが参照変換として、
var transform = {"tag":"div","children":function(){
return(json2html.transform(this.orders,orderTransform));
}};
注this.orders
へthis
の変更:
<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