繁体   English   中英

使用参数未计算的基因剔除

[英]Knockout Computed with Parameter not updated

在MVC应用程序中,im从数据库生成多个下拉列表:

<select data-bind="options: findGroup(1).items(),
                        optionsText: 'country',
                        optionsValue: 'id',
                        value: selectedItem(1),
                        event: { change: selectionChange }"></select>

我需要在代码中选择当前值,但要调试使用跨度的im:

<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,保罗

您的函数返回一个计算值,因此需要像

http://jsfiddle.net/LGveR/18/

this.selectedItem(1)().country

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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