Select one option in rendered


#1

in my template,i have a select

<select name="component" id="component"  >
    {{#each componentList}}
      <option value="{{_id}}">{{name}}</option>
    {{/each}}
</select>

in template helper ,i have a componentList (writen in coffeescript).
code one

Template.adminEdit.helpers
  'componentList': ->
     Components.find()

code two

Template.adminEdit.helpers
      'componentList': ->
         [
            {_id: '6K8unLsmxSFFo33zx', name: 'wordpress'}
            {_id: '9hCGkpq7kEG4WnReA', name: 'drupal'}
            {_id: 'vASDPxAYqhS6ofi9P', name: 'ngnix'}
          ]

only use code two ,i can select one option in rendered

$("#component").val("9hCGkpq7kEG4WnReA")

but i am sure the Components.find() is the same result.
how can i change code one to work

thanks!


#2

As far as I can see, code one should work (if Components.find() actually returns the correct values, which you can check by inserting console.log(Components.find().fetch()) in your helper).


#3

i check

console.log(Components.find().fetch())

result is 0.

i realize may be the subscription isn’t ready

thank you steve