How to Display with JSRENDER JSON without Field Na

2019-08-25 06:50发布

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

标签: jsrender
1条回答
Emotional °昔
2楼-- · 2019-08-25 07:22

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.)

查看更多
登录 后发表回答