How to Display with JSRENDER JSON without Field Names

∥☆過路亽.° 提交于 2019-12-12 00:43:11

问题


how to display a JSON with only Values and no Fieldnames with JSRENDER in a Table?

JSON

var JSON = { "ID1":["VALUE1","VALUE2","VALUE3"],"ID2":["VAL2-1","VAL2-2","VAL2-3"]}

The Table Result should be:

<tr>
 <td>ID1</td>
 <td>VALUE1</td>
 <td>VALUE2-3</td>
</tr>

<tr>
 <td>ID2</td>
 <td>VAL2-1</td>
 <td>VAL2-3</td>
</tr>

What is the Syntax of JSRENDER to fill the td's with the value?

Kidn Regards

Rene


回答1:


JsRender has a {{props}} tag for iterating through fields/properties of an object.

See the API topic and samples here: http://www.jsviews.com/#propstag

You can use it in this template:

<script id="myTmpl" type="text/x-jsrender">
  {{props ...}}
    <tr>
      <td>{{:key}}</td>
      {{for prop}}
        <td>{{:}}</td>
      {{/for}}
    </tr>
  {{/props}}
</script>

I created a fiddle here: http://jsfiddle.net/BorisMoore/j7eE8/

(See here for more about helpers: http://www.jsviews.com/#helpers. If you want you can pass the helper in with the render call, as context, rather than registering it with $.views.helpers.)



来源:https://stackoverflow.com/questions/18096069/how-to-display-with-jsrender-json-without-field-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!