Anoop Kumar
Anoop Kumar

Reputation: 488

Ember JS: select list with selected value

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

  1. Why is it giving false even if value and type both are same.
  2. Is there any way to just check for value like a == b.

Upvotes: 0

Views: 381

Answers (1)

TBieniek
TBieniek

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

Related Questions