kthx再见..............................
Knockout 中的内置油门扩展器正如其名称所示:它会限制更新。看来我想做点别的事情。在模糊字段时立即更新值,但否则会在键入时限制输入。
我最终想出的解决方案是调整内置油门扩展器并将其添加为自定义扩展器:
ko.extenders.smart_throttle = function(target, timeout) {
target['throttleEvaluation'] = timeout;
target['lastUpdatedValue'] = null;
var writeTimeoutInstance = null;
return ko.computed({
'read': target,
'write': function(value) {
if (value == target()) {
clearTimeout(writeTimeoutInstance);
target(target['lastUpdatedValue']);
return;
}
clearTimeout(writeTimeoutInstance);
target['lastUpdatedValue'] = value;
writeTimeoutInstance = setTimeout(function() {
target(value);
}, timeout);
}
});
}
Akshat 的回答仍然完美地解决了我原来的问题。很抱歉没有正确地表述它。