Firefox 中与rateLimit 和 valueUpdate afterkeydown 绑定的淘汰值会删除最后输入的字母
我创建了一个 JS Fiddle 来显示这个问题: https://jsfiddle.net/evanlarsen/e8bj9upf/7/
在文本框中输入时它应该显示您在其下方键入的内容。这在 google chrome 浏览器中工作正常,但在使用 Firefox 时,您输入的最后一个字母会被删除。
HTML
<div id="app">
<input type="text" data-bind="value: value, valueUpdate: 'afterkeydown'" />
<div data-bind="text: value"></div>
</div>
Javascript
const App = function(){
this.value = ko.observable('');
this.value.extend({ rateLimit: { timeout: 800, method: 'notifyWhenChangesStop' } });
}
const app = new App();
ko.applyBindings(app, document.getElementById('app'));
如何让 Firefox 停止删除最后一个字母?我希望在每次按键后更新可观察值,但同时也限制更新,这样它不会在每次按键时更新,而是仅在 800 毫秒不再按键后更新。
I created a JS Fiddle to show the issue:
https://jsfiddle.net/evanlarsen/e8bj9upf/7/
When typing in the textbox it should show what you type just below it. This works fine in google chrome browser but when using Firefox the last letter of whatever you type gets dropped.
HTML
<div id="app">
<input type="text" data-bind="value: value, valueUpdate: 'afterkeydown'" />
<div data-bind="text: value"></div>
</div>
Javascript
const App = function(){
this.value = ko.observable('');
this.value.extend({ rateLimit: { timeout: 800, method: 'notifyWhenChangesStop' } });
}
const app = new App();
ko.applyBindings(app, document.getElementById('app'));
How can I get firefox to stop dropping the last letter? I would like to have the observable updated after every keydown but also throttle the update so its not updated on every key press but only after 800 milliseconds of no more key presses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法在 Firefox 98.0 中重现该问题,但您最好还是使用
textInput
绑定。实际上在 文档中建议这样做。所以:
https://jsfiddle.net/thebluenile/xydwpvez/
Can't reproduce the issue with Firefox 98.0, but you're better off using the
textInput
binding anyway. It's actually recommended in the docs.So:
https://jsfiddle.net/thebluenile/xydwpvez/
尝试使用“afterkeyup”,这可以满足您的要求吗?
这篇文章有一个 JSFiddle,它可以帮助实现您想要的延迟效果,利用速率限制,在 800 毫秒;
Knockout.js 延迟值更新:afterkeydown
Try using 'afterkeyup', would this work for your requirement?
This post has a JSFiddle which could help achieve what you want to do with the delay also, utilising rateLimit, at 800 ms;
Knockout.js delay valueUpdate: afterkeydown