0
试图从数组中打印2个项目的所有组合。在两次迭代相同阵列时,把手会打印错误的东西
var source = document.getElementById("entry-template").innerHTML;
var template = Handlebars.compile(source);
var context = {
colors: ['red', 'blue', 'green']
};
var html = template(context);
document.getElementById("output").innerHTML = html;
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.11/handlebars.js"></script>
<script id="entry-template" type="text/x-handlebars-template">
output:
{{#colors}}
{{#../colors}}
color1: {{../this}} color2: {{this}};
{{/../colors}}
{{/colors}}
</script>
<pre id="output">
</pre>
这里是一个Codepen Demo
的可能的复制[../this返回内环当父和子具有相同的值的内部视图对象(https://stackoverflow.com/questions/40935524/ this-returns-the-view-object-inside-inner-loop-when-the-the-and-child-have) – 76484