udh*_* UK 0 handlebars.js handlebarshelper
我有两个清单:
var one =["test","test1","test2"];
var two =["temp","temp1","temp2",""temp3","temp4"];
Run Code Online (Sandbox Code Playgroud)
我在下面尝试了一些东西,但它不起作用。
<table>
{{#each one}}
<td>{{this}}</td>
<td>
<select>
{{#each two}}
<option>{{this}}</option>
{{/each}}
</select>
</td>
{{/each}}
</table>
Run Code Online (Sandbox Code Playgroud)
问题是“两个”数组的范围在第一个每个块之外。
试试这个:
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>
Run Code Online (Sandbox Code Playgroud)