嵌套每个都不起作用

时间:2017-03-28 09:40:53

标签: handlebars.js handlebarshelper

我有两个清单:

var one =["test","test1","test2"];
var two =["temp","temp1","temp2",""temp3","temp4"];

我在下面尝试了一些东西,但它没有用。

<table>
{{#each one}}
  <td>{{this}}</td>
  <td>
    <select>
     {{#each two}}
       <option>{{this}}</option>
     {{/each}}
    </select>
  </td>
{{/each}}
</table>

2 个答案:

答案 0 :(得分:4)

问题是“两个”数组的范围是在每个块的第一个区域之外。

请改为尝试:

var context = {
 one : ["test","test1","test2"],
 two : ["temp","temp1","temp2",""temp3","temp4"]
};


<table>
{{#each context.one}}
  <td>{{this}}</td>
  <td>
    <select>
     {{#each ../two}}
       <option>{{this}}</option>
     {{/each}}
    </select>
  </td>
{{/each}}
</table>

答案 1 :(得分:1)

每个块的第二个语法错误。它应该是{{#each two}}而不是{{each}}