Knockout计算参数未更新

时间:2014-06-30 10:47:58

标签: javascript jquery knockout.js

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

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

我需要在我的代码中选择当前选项,但是对于Debugging,使用span:

来实现
<span data-bind="text: 'Computed Selected Country: ' + selectedItem(1).country"></span><br />

findgroup(x)和selectedItem(x)是我的ViewModel中的全局函数,而所有下拉列表都是相同的。

selectedItem(x)应返回当前所选的下拉选项。 selectedItem(x)是一个返回计算出的knockout observable的函数。 selectedItem(x)总是返回&#34; undefined&#34;,无法找出原因......

完整示例:http://jsfiddle.net/LGveR/17/

TIA, 保罗

1 个答案:

答案 0 :(得分:1)

你的函数返回一个计算所以需要像

那样执行

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

this.selectedItem(1)().country
相关问题