与文档所暗示的相反,该valueUpdate
参数没有“定义 KO 应该使用哪个浏览器事件来检测更改”,默认值为“更改”,它允许您提供一个事件或应该捕获的可能事件列表,除了总是被抓住的“变化”。
相关代码为:
// Always catch "change" event; possibly other events too if asked
var eventsToCatch = ["change"];
var requestedEventsToCatch = allBindingsAccessor()["valueUpdate"];
if (requestedEventsToCatch) {
if (typeof requestedEventsToCatch == "string") // Allow both individual event names, and arrays of event names
requestedEventsToCatch = [requestedEventsToCatch];
ko.utils.arrayPushAll(eventsToCatch, requestedEventsToCatch);
eventsToCatch = ko.utils.arrayGetDistinctValues(eventsToCatch);
}
这种行为实际上是在:https ://github.com/SteveSanderson/knockout/issues/102
https://github.com/SteveSanderson/knockout/commit/843420a6f801b17dd357880b359a67fa53647999
看起来文档还没有更新。我希望人们在需要时必须要求更改,并且文档告诉他们以下内容:
“事件列表,我们建议包括'change',通过[]禁用自动更新模型”