javascript - Adding Data-Bind to Bootrstrap Dropdown - Stack Overflow

I am trying to pull in a list of values through data-bind into a Twitter Bootstrap dropdown.<div cla

I am trying to pull in a list of values through data-bind into a Twitter Bootstrap dropdown.

<div class="btn-group">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            Action <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" data-bind="options: artists, optionsText: 'name', optionsValue: 'id', value:selectedArtistId">
            <li></li>
          </ul>
</div>

I came across Knockout_bootstrap JS but am not sure it works with drop downs

/

(no example provided)

I am trying to pull in a list of values through data-bind into a Twitter Bootstrap dropdown.

<div class="btn-group">
          <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            Action <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" role="menu" data-bind="options: artists, optionsText: 'name', optionsValue: 'id', value:selectedArtistId">
            <li></li>
          </ul>
</div>

I came across Knockout_bootstrap JS but am not sure it works with drop downs

http://billpull.github.io/knockout-bootstrap/

(no example provided)

Share Improve this question asked Nov 15, 2013 at 0:37 Joe IsaacsonJoe Isaacson 4,1327 gold badges32 silver badges40 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

HTML List vs HTML Select
The bootstrap dropdown is an html list.

<ul>
  <li></li>
</ul>

The knockout js options binding is a binding for html select elements.

<select>
   <option></option>
</select>

I cannot tell for sure what you want to do, but what you are currently doing is adding the knockout options binding to a <ul>, when the binding is supposed to be for a <select>.

Live Example in JS Bin
Here is an exmaple in jsbin that uses knockout for binding in both scenarios.

http://jsbin./ITOZUPI/1/edit

part of HTML with ko data-bindings

<div class="btn-group">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            Action <span class="caret"></span>
          </button>
  <ul class="dropdown-menu" role="menu" data-bind="foreach: my.VM.Artists">
    <li><a role="menuitem" tabindex="-1" href="#" data-bind="text: artistName, click: getTheArtist"></a></li>
</ul>
</div>

  <p>&nbsp;</p>

  <select data-bind="options: my.VM.Artists, 
                 optionsCaption: 'Please select an Artist...',  
                 optionsText: 'artistName', 
                 optionsValue: 'artistId',
                 value: my.VM.artist_selected"></select>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745333757a4623007.html

相关推荐

  • javascript - Adding Data-Bind to Bootrstrap Dropdown - Stack Overflow

    I am trying to pull in a list of values through data-bind into a Twitter Bootstrap dropdown.<div cla

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信