这不按预期工作:
<!-- {{>io_cmd_button}} -->
{{#if (button.type === 'output')}}
{{#button.pins}}
<div style="width: 40%; margin: 10px; border: 1px solid yellowgreen; padding: 20px">
<p> RPi led: <input id='rpi-command-{{button.type}}' type="checkbox" value="{{.}}" />
</div>
{{/button.pins}}
{{else}}
<h3> this is input pin, only status will be shown </h3>
{{/if}}
<!-- {{/io_cmd_button}} -->
通过否定条件并交换if / else块的主体,保持相同的逻辑,代码变为如下并按预期工作:
<!-- {{>io_cmd_button}} -->
{{#if (button.type !== 'output')}}
<h3> this is input pin, only status will be shown </h3>
{{else}}
{{#button.pins}}
<div style="width: 40%; margin: 10px; border: 1px solid yellowgreen; padding: 20px">
<p> RPi led: <input id='rpi-command-{{button.type}}' type="checkbox" value="{{.}}" />
</div>
{{/button.pins}}
{{/if}}
<!-- {{/io_cmd_button}} -->
为什么呢?有什么不同?