【发布时间】:2014-06-30 19:03:52
【问题描述】:
在 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) 是一个返回计算出的可观察到的淘汰赛的函数。 selectedItem(x) 总是返回“未定义”,不知道为什么......
完整示例:http://jsfiddle.net/LGveR/17/
TIA, 保罗
【问题讨论】:
标签: javascript jquery knockout.js