handlebars.js - 遍历 json 数组以确定是否应选中复选框
handlebars.js - looping over json array to determine if checkbox should be checked
我无法更改数据源,我必须使用提供的内容。
数据如下所示:
[
[190, "some title here", 0, 100, 1, "https://www.somedomainhere.com", "", 8]
]
值 100 之后的 1
可以是 1、2 或 3。在我这边,这与要选择的 3 个单选选项中的 1 个有关。
{{#each myData}}
<input type="radio" id="radio53" name="activityTypeID" value="1" {{#if_eq 4 1}}checked{{/if_eq}}>
<input type="radio" id="radio54" name="activityTypeID" value="3" {{#if_eq 4 3}}checked{{/if_eq}}>
<input type="radio" id="percentOfMax" name="activityTypeID" value="2" {{#if_eq 4 2}}checked{{/if_eq}}>{{/each}}
我正在尝试使用助手class,但愿意接受此处的其他建议
我不知道如何使用车把评估 4
,这就是我被困的地方。如果仅在我的车把模板中使用 {{4}}
,它将使用我在此 post 顶部提供的 json 字符串显示为 1
。我使用 handlebars.js 的经验非常有限,但我非常喜欢使用它,并期待看到如何解决这个问题。
这比我预期的要容易得多,我只需要在它周围加上 []
就可以了:
{{#if_eq [4] 1}}checked{{/if_eq}}
不错!
做这些
{{#if_eq [4] 1}}checked{{/if_eq}}
我无法更改数据源,我必须使用提供的内容。
数据如下所示:
[
[190, "some title here", 0, 100, 1, "https://www.somedomainhere.com", "", 8]
]
值 100 之后的 1
可以是 1、2 或 3。在我这边,这与要选择的 3 个单选选项中的 1 个有关。
{{#each myData}}
<input type="radio" id="radio53" name="activityTypeID" value="1" {{#if_eq 4 1}}checked{{/if_eq}}>
<input type="radio" id="radio54" name="activityTypeID" value="3" {{#if_eq 4 3}}checked{{/if_eq}}>
<input type="radio" id="percentOfMax" name="activityTypeID" value="2" {{#if_eq 4 2}}checked{{/if_eq}}>{{/each}}
我正在尝试使用助手class,但愿意接受此处的其他建议
我不知道如何使用车把评估 4
,这就是我被困的地方。如果仅在我的车把模板中使用 {{4}}
,它将使用我在此 post 顶部提供的 json 字符串显示为 1
。我使用 handlebars.js 的经验非常有限,但我非常喜欢使用它,并期待看到如何解决这个问题。
这比我预期的要容易得多,我只需要在它周围加上 []
就可以了:
{{#if_eq [4] 1}}checked{{/if_eq}}
不错!
做这些
{{#if_eq [4] 1}}checked{{/if_eq}}