停止键盘输入后应触发的 Dojo 事件

Dojo events that should trigger after stopping the keyboard typing

我有文本框,目前我已经附加了 DOJO 事件,每次按键都会触发事件,但是 DOJO 中是否有任何事件只有在键盘输入完成后才会触发。

<div  class="cell">
<input type="search" name="searchbox" id="searchbox" placeholder="Search Location" data-dojo-attach-event = "keypress:_getData"/>
</div>

_getData:function(){
         alert("function triggered");    
         }

此按键是来自 dojo/keys.

的事件

Currently if i type "STACK" the event is triggering 5 times instead it should trigger one time after typing full word or it should trigger only after he stops typing.

你必须使用去抖动机制。 如果你使用 Dojo 1.10,你可以使用 dojo/on/debounce:

on(dom.byId('searchbox'), 'keypress', debounce(this._getData));

详情可以看单元测试: https://github.com/dojo/dojo/blob/db66e918cd5a736fa4023741ace82e1bdc0fb612/tests/unit/on/debounce.js