0

试图使这项工作。我需要在新 TD 之间显示 FIRST_NAME 和 LAST_NAME 值。该值存储在数据项的对象中。我似乎无法循环遍历子对象。

模板示例

<script id="row_tmpl" type="text/x-jsrender">
      <tr id="{{>id}}">
        <td class="textC">{{>id}}</td>
        <td class="">{{>email}}</td>
        {{for data}}

            ??????

        {{/for}}
      </tr>
</script>

下面是发送到模板的 json 对象的示例(实际上,data.results 是发送到模板的)

{
  "results":[
     {
     "id":"1",
     "email":"aaaa@test.com",
     "data":{
        "1":{
           "first_name":{
              "value":"Name 1",
              "public":"1",
              "field":"1",
              "mandatory":"1",
              "possible_value":"",
              "type":"text"
           },
           "last_name":{
              "value":"Name 2",
              "public":"1",
              "field":"2",
              "mandatory":"1",
              "possible_value":"",
              "type":"text"
           }
        }
     }
  },
  {
     "id":"2",
     "email":"test2@test.com",
     "data":{
        "2":{
           "first_name":{
              "value":"Name 3",
              "public":"0",
              "field":"1",
              "mandatory":"1",
              "possible_value":"",
              "type":"text"
           },
           "last_name":{
              "value":"Name 4",
              "public":"0",
              "field":"2",
              "mandatory":"1",
              "possible_value":"",
              "type":"text"
           }
        }
     }
  }
  ]
}
4

1 回答 1

1

这是一个结构不佳的回应。我不需要知道idofdata的父级来访问它的子级。另外,data不是数组。

<script id="row_tmpl" type="text/x-jsrender">
      <tr id="{{>id}}">
        <td class="textC">{{>id}}</td>
        <td class="">{{>email}}</td>
        <td class="">{{>data.{{:id}}.first_name.value}}</td>
        <td class="">{{>data.{{:id}}.lastt_name.value}}</td>
      </tr>
</script>
于 2012-10-03T22:37:22.817 回答