javascript - 为什么我在 Handlebars 中存在范围问题?
问题描述
在我的 Handlebars 代码中,我在 if 块(或 ifCond 块)中有一个未定义的变量,但没有 if 块我有一个很好的结果。
这是我的代码:
{{#each array}}
<select>
<option {{#if variable}}{{else}} selected="selected"{{/if}}>- </option>
{{#for x}}
<option {{#ifCond ../variable this}} selected="selected"{{/ifCond}} value="{{this}}">{{this}}% {{../variable}}</option>
{{/for}}
</select>
{{/each}}
在第 5 行的 % 之后,我有一个很好的结果。
感谢所有帮助!
解决方案
您可以使用反转 if 而不是使用空 if#unless
{{#unless variable}} selected="selected"{{/unless}}
推荐阅读
- reactjs - Too Many Re Renders React JS - useState
- visual-studio-code - 让空格像 VS Code 中的选项卡一样起作用
- keras - keras 中的 ModelCheckpoint 与旧模型比较
- javascript - PWA - Angular:创建用于选择 PIN 码的自定义小键盘
- entity-framework - 带有 Like 子句的 EF Core 原始查询
- reactjs - 添加 react 路由后无法访问 redux store。未调用 MapStateToProps
- vuejs2 - 如何设置 Buefy 按钮的样式,使其看起来像文本链接
- android - 如何设置TextInputLayout的下划线颜色
- r - 如何从字符串中提取括号到新列中
- mysql - 我应该使用冗余数据来减少数据库/服务器的压力吗?