set selected option on select option binding

61 views
Skip to first unread message

Ricky

unread,
May 20, 2016, 9:39:51 AM5/20/16
to KnockoutJS
Hi

I have : 

<select id="selectEnv" class="form-control input-sm" data-bind="foreach: availableEnvironments" onchange="main.changeEnvironment()">
   <option data-bind="text: name, value: id, disable: disabledEnvironment, css: unreachableCSS"/>
</select>                    

I have a property string set to "selected" or "".
Where can i put this property ?
There is no : 
- selected: isSelected
- attr {selected: isSelected }

Thx in advance
 

Ricky

unread,
May 23, 2016, 2:39:54 AM5/23/16
to KnockoutJS
No one know ?? 
I just need to set "selected" property to 1 item

Gunnar Liljas

unread,
May 23, 2016, 5:32:05 AM5/23/16
to knock...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "KnockoutJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knockoutjs+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ricky

unread,
May 24, 2016, 8:01:09 AM5/24/16
to KnockoutJS
The documentation is totally wrong


Le vendredi 20 mai 2016 15:39:51 UTC+2, Ricky a écrit :

Gunnar Liljas

unread,
May 24, 2016, 10:51:36 AM5/24/16
to knock...@googlegroups.com
No, it's perfectly correct, but you're not using the built-in concepts.

Maybe what you need is the prop binding, found here:


--

Michael Best

unread,
May 24, 2016, 5:14:10 PM5/24/16
to KnockoutJS
You should use the value binding to select an item:

<select id="selectEnv" class="form-control input-sm" data-bind="foreach: availableEnvironments, value: selectedItem" onchange="main.changeEnvironment()">
  <option data-bind="text: name, value: id, disable: disabledEnvironment, css: unreachableCSS"/>
</select>

-- Michael
Reply all
Reply to author
Forward
0 new messages