kendo-ui自动完成扩展
我正在尝试扩展kendo-ui自动完成控制:我想在用户按下Enter键时开始搜索,因此基本上我必须检查keydown事件上的用户输入. 我尝试使用以下代码捕获keydown事件:
I'm trying to extend the kendo-ui autocomplete control: I want the search start when te user hit enter, so basically I've to check the user input on keydown event. I've tried to catch the keydown event with this code:
(function($) {
ui = kendo.ui,
Widget = ui.Widget
var ClienteText = ui.AutoComplete.extend({
init: function(element,options) {
var that=this;
ui.AutoComplete.fn.init.call(this, element, options);
$(this).bind('keydown',function(e){ console.log(1,e); });
$(element).bind('keydown',function(e){ console.log(2,e); });
},
options: {
[...list of my options...]
},
_keydown: function(e) {
console.log(3,e);
kendo.ui.AutoComplete.fn._keydown(e);
}
});
ui.plugin(ClienteText);
})(jQuery);
没有任何绑定事件被调用,只有_keydown被调用,然后我做错了什么,因此无法调用自动完成的正常" keydown事件. 我已经看到了很多扩展基本窗口小部件然后创建复合窗口小部件的示例,但是我对此并不感兴趣,我只想向现有窗口小部件添加功能. 有人可以告诉我我在做什么错吗?
None of the binded events gets called, only the _keydown, and then I'm doing something wrong and cannot call the autocomplete "normal" keydown event. I've seen a lot of examples that extend the base widget and then create a composite widget, but I'm not interested in doing that, I only want to add a functionality to an existing widget. Can someone show me what I'm doing wrong?
谢谢!
此代码实际有效:
(function($) {
ui = kendo.ui,
ClienteText = ui.AutoComplete.extend({
init: function(element,options) {
ui.AutoComplete.fn.init.call(this, element, options);
$(element).bind('keydown',function(e){
var kcontrol=$(this).data('kendoClienteText');
if (e.which === 13) {
kcontrol.setDataSource(datasource_clientes);
kcontrol.search($(this).val());
} else {
kcontrol.setDataSource(null);
}
});
},
options: {
name: 'ClienteText',
}
});
ui.plugin(ClienteText);
})(jQuery);
但是我不知道这是否是正确的方法.
but I don't know if it's the correct way to do it.