Pergunta

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

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top