【发布时间】:2017-06-21 08:48:16
【问题描述】:
我正在将 Knockout 与 MVC Core Web 应用程序一起使用。在我的 UI 中,我有几个输入文本字段。例如 FirstName、LastName 和 FullName。
我将 FullName 设置为计算的 observable。这是我的问题。 案例 1:基于某些条件,我想使用 FirstName 和 LastName 数据来计算 FullName。 (这是示例中显示的常见情况)。
案例 2:基于某些条件,我想读取用户可以在 FullName 文本字段中输入的输入。有人可以帮助我如何做到这一点。
function AppViewModel() {
this.firstName = ko.observable('Bob');
this.lastName = ko.observable('Smith');
if(somecondition)
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
} else {
return somevalueEnterned in the text box
}, 这个); }
【问题讨论】: