Reputation: 488
I am trying to create a select component. In which I need to select an option based on the value in object.
Found something similar here
Implemented same:
<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>
Here sourceType.id
is id
for current option and selectedOption
is sourceType reference in source object. Type is number in REST service response for both of them.
When I tried to print value of eq sourceType.id selectedOption
in option it is giving me false. Then I checked for eq
documentation, it is a === b
a == b
. Upvotes: 0
Views: 381
Reputation: 4937
Is there any way to just check for value like a == b.
You can implement a custom helper that does this (see 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;
});
Upvotes: 1