gpt4 book ai didi

javascript - Ember JS : select list with selected value

转载 作者:行者123 更新时间:2023-12-03 02:48:54 24 4
gpt4 key购买 nike

我正在尝试创建一个选择组件。其中我需要根据对象中的值选择一个选项。

发现类似的东西here

实现相同:

<select>
<option value="" selected disabled >Select </option>
{{#each sourceTypes as |sourceType|}}
<option value={{sourceType.id}} selected={{if (eq sourceType.id selectedOption) 'true'}}>{{sourceType.type}}</option>
{{/each}}
</select>

这里sourceType.id是当前选项的idselectedOption是源对象中的sourceType引用。类型是两者的 REST 服务响应中的编号。

当我尝试在选项中打印 eq sourceType.id selectedOption 的值时,它给了我 false。然后我检查了 eq 文档,它是 a === b

  1. 即使值和类型相同,为什么也会给出 false。
  2. 有没有办法只检查像a == b这样的值。

最佳答案

Is there any way to just check for value like a == b.

您可以实现一个自定义助手来执行此操作(请参阅 https://guides.emberjs.com/v2.17.0/templates/writing-helpers/ )

import { helper } from "@ember/component/helper"

export default helper(function([a, b]) {
return a == b;
});

关于javascript - Ember JS : select list with selected value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47979848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com