我是jsrender的新手,所以如何将对象数组打印为json
<ul>{{for my_array}}
<li>{{:.toString()}}</li>
{{/for}}
</ul>
答案 0 :(得分:1)
查看{{props}} tag doc主题。
您还可以使用{{jsonview}}标记控件 - 请参阅JsViews主题:
{{jsonview}}可以与JsRender一起使用(即不进行JsViews数据绑定),如下例所示:
<head>
...
<script src="//www.jsviews.com/download/jsrender.js"></script>
<script src="//www.jsviews.com/download/sample-tag-controls/jsonview/jsonview.js"></script>
<link href="//www.jsviews.com/download/sample-tag-controls/jsonview/jsonview.css" rel="stylesheet">
</head>
<body>
<div id="team"></div>
<script id="myTmpl" type="text/x-jsrender">
{{jsonview/}}
</script>
<script>
"use strict";
var team = {
members: {
m1: {name: "Robert"},
m2: {name: "Sarah"}
}
};
$("#team").html($.templates("#myTmpl").render(team));
</script>
</body>