简体   繁体   中英

binding knockout dropdown in foreach

I have a dropdown inside a foreach

 <tbody data-bind="foreach:  Details">
 <tr style="border: none">
 <select style="width: 130px" 
         data-bind=" optionsCaption: 'Choose...', 
          options: $data.filteredList, optionsText: 'number',
          optionsValue: 'id'">
 </select>
 </tr>

This binding does not seem to work. When I debug I can see that the filter is updating but I never get any thing in the dropdown.

I added this:

<pre data-bind="text: ko.toJSON($data, null, 2)"></pre>

This is the result:

{
  "Seed": 1,
  "filteredList": [
    {
      "id": "a",
      "number": "12"
    },
    {
      "id": "b",
      "number": "12"
    } 
}

And I can see that the filter values are changing.

Why would the dropdown be empty?

只要改变$data.filteredList$root.filteredList的结合,如果filteredList是其成员的ModelView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM