在 MVC 应用程序中,我从数据库生成多个下拉列表:
<select data-bind="options: findGroup(1).items(),
optionsText: 'country',
optionsValue: 'id',
value: selectedItem(1),
event: { change: selectionChange }"></select>
我需要在代码中选择当前的值,但为了调试目的,我使用跨度:
<span data-bind="text: 'Computed Selected Country: ' + selectedItem(1).country"></span><br />
findgroup(x) 和 selectedItem(x) 是我的 ViewModel 中的全局函数,而这些函数对于所有下拉菜单都是相同的。
selectedItem(x) 应返回下拉列表中当前选定的选项。 selectedItem(x) 是一个返回计算出的 knockout 可观察值的函数。 selectedItem(x) 总是返回“未定义”,无法弄清楚为什么......
完整示例:http://jsfiddle.net/LGveR/17/
TIA, 保罗
最佳答案
关于javascript - knockout 计算参数未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24488382/