Javascript 使用未更新的参数计算淘汰

Javascript 使用未更新的参数计算淘汰,javascript,jquery,knockout.js,Javascript,Jquery,Knockout.js,在MVC应用程序中,im从数据库生成多个下拉列表: <select data-bind="options: findGroup(1).items(), optionsText: 'country', optionsValue: 'id', value: selectedItem(1), event:

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

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

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

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

findgroup(x)和selectedItem(x)在我的ViewModel中是全局函数,而对于所有下拉列表,它们是相同的

selectedItem(x)应返回下拉列表中当前选定的选项。 selectedItem(x)是一个函数,用于返回计算出的敲除可观测值。selectedItem(x)总是返回“未定义”,无法找出原因

完整示例:

蒂亚,
Paul

您的函数返回一个计算值,因此需要执行如下操作:


很好,谢谢,很明显,但被忽略了:)顺便说一句,每次选择改变时都创建一个新的计算机不是很好。计算结果应跟踪更改,但不应重新创建
this.selectedItem(1)().country