我怎样才能在一个viewModel变量可变的变量? (淘汰赛)
正如截图显示,有一个视图模型称为我的网页应用程序,它有一个名为“isShortlisted”变量,表示应用程序是否入围与否。它的声明如下:
self.applications = ko.observableArray(@Html.Json(Model.ApplicationCompatibilities.Select(o => o.JsonForm)) || []);
,我需要isShortlisted设置为可观察的,因为我希望我的按钮有这个条件
<form id="shortlistForm" data-bind="style: { display: application.isShortlisted === false ? 'inline-block' : 'none'}>
<form id="unshortlistForm" data-bind="style: { display: application.isShortlisted === true ? 'inline-block' : 'none'}>
(the form above shows up when "isShortlisted" is false and the one below shows when it's true(when clicked))
当“isShortlisted”值改变立即显示变化(和唯一可观测更新我试着做立即的变化)
是:
self.isShortlistedObservable = ko.observable(self.applications.application.isShortlisted);
并给我一个错误
Cannot read property 'isShortlisted' of undefined
总之,我可以做我该变量观察到,以便更新状态,每当值被改变? PLZ告诉我正确的语法
感谢您的回答。当我这样做时,我不会再犯错误,但我不明白它会如何工作。 “self.applications()[0] .application.isShortlisted”将返回第一个对象的“isShortlisted”。我该如何访问其他的?因为我假设通过将“isShortlisted”设置为true来使shortlistForm可见 – Dukakus17
这是我不完全了解的问题的一部分。也许如果您添加了更多描述或相关代码块,我可以更好地回答您的问题? –