【发布时间】:2013-11-20 16:59:48
【问题描述】:
这里有两个文本框和一个跨度是通过淘汰赛绑定的。我得到的例子很容易理解。这是代码。
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth"));
当代码运行时,所传递的任何值都会被反映,但是当我更改一个文本框值时,当keyup 发生时更改的数据不会立即反映,但是当焦点更改时,更改的数据会反映在跨度中。因此,如果我想更改 keyup 上的数据,请指导我,然后我需要更改代码。谢谢
【问题讨论】:
标签: knockout.js