Knockout <select> dropdown list using knockout visibility for option items?

2,100 views
Skip to first unread message

winsor...@gmail.com

unread,
Sep 30, 2013, 1:13:27 PM9/30/13
to knock...@googlegroups.com

I am using Knockout in a MVVM single page app environment and am trying to create a dropdown list using a knockout select.  I'd like to be able to BOTH:

1) individually make items in the options list visible which I have accomplished using a <select> and then a knockout containerless ko: foreach around my <options> element like this:

<select class="selectpicker" show-tick data-bind="attr:{name: categoryTypeName, id: categoryTypeName, title: categoryTypeName, dataIndex:$index}, event:{change:onChange}">
    <!--ko foreach: categories -->                                           
        <option data-bind="value: categoryID, text: name, visible:IsVisible"></option>
    <!--/ko-->
 </select>

AND

2) have a selected value from an arbitrary JavaScript object which I have accomplished using options, optionsText, optionsValue and value defined  in my select element like this:

<select id="inputCategory" data-bind="attr: {name: categoryTypeName, id: categoryTypeName, title: categoryTypeName,         dataIndex:$index}, options: $root.visibleCategories(), optionsText: 'name',  optionsValue:'categoryID', value: $root.selectedCategoryId()[$index()], event: {change: $root.onCategoryChange } " >
</select>

Both of these work on their own , but they use different select element structure.  I'd like to do both but can't figure out how to both individually apply visibility to items in my options list AND have the select format that enables me to define a selected value.

Is there a way to do both of these together?

Gunnar Liljas

unread,
Sep 30, 2013, 8:29:50 PM9/30/13
to knock...@googlegroups.com


2013/9/30 <winsor...@gmail.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/groups/opt_out.

winsor...@gmail.com

unread,
Oct 1, 2013, 10:39:40 AM10/1/13
to knock...@googlegroups.com
Thank you for the pointer - I will review.  For now I just changed my approach and created a modified array with the correct items for "options" rather than try to make some items visible and some not visible in the original "options" array.
Reply all
Reply to author
Forward
0 new messages