knockout.js: using a containerless foreach on a <select> fails in Internet Explorer 8

前端 未结 2 1407
野趣味
野趣味 2020-12-06 12:59

In RP Niemeyer\'s article Knockout.js Performance Gotcha #3 - All Bindings Fire Together, an approach to building a dropdown list is provided:


                        
    
提交评论

  • 2020-12-06 13:21

    Although this is an issue, there is really no need to use a 'foreach' here. Knockout includes the 'options' binding for a select that quite happily works in IE8.

    Please see the documentation here: http://knockoutjs.com/documentation/options-binding.html

    <select data-bind="value: selectedOption">
        <!-- ko foreach: options -->
        <option data-bind="attr: { value: id }, text: name"></option>
        <!-- /ko -->
    </select>
    

    Can be changed to:

    <select data-bind="value: selectedOption, options: options, optionsText: function(item) {return item.name}, optionsValue: function(item) {return item.id}></select>
    

    Hope this helps.

    0 讨论(0)
  • 提交回复
    热议问题