YUI自动完成事件,怎么办? [英] YUI AutoComplete events, how to?
问题描述
如何捕捉AutoComplete触发的事件?该文档说明当用户从列表中选择一个项目时触发select事件。我想附加一个函数到该事件。如何做?
这是插件方法的一个例子, http://tivac.com/yui3/so/skladjfyhafjk_autocomplete.htm
在您首次将自动填充插入到输入中时,只需将事件处理程序作为配置的一部分。
Y.one(#ac ).plug(Y.Plugin.AutoComplete,{
resultHighlighter:'phraseMatch',
source:['foo','bar','baz'],
on:{
select:function(e){
console.log(arguments); // TODO:REMOVE DEBUGGING
}
}
});
您还可以使用其附加的命名空间(ac)插入元素后, 。
Y.one(#ac)。ac.on(select,function(){
console.log(post-plugin event subscription); // TODO:REMOVE DEBUGGING
});
如果你使用它作为一个类,它的工作原理如下。
var ac = new Y.AutoComplete({
inputNode:'#ac',
source:['foo','bar ','baz']
});
ac.on(select,function(){
console.log(Class event subscription); // TODO:REMOVE DEBUGGING
});
I'm using YUI 3.3.0 and the AutoComplete widget. I'm entirely new to YUI. Here's the thing. I have AutoComplete working.
How do I catch an event fired by AutoComplete? The documentation states that a select event is fired when a user selects an item from the list. I want to attach a function to that event. How do I do that?
Here's an example for the plugin approach, http://tivac.com/yui3/so/skladjfyhafjk_autocomplete.htm
Simply pass your event handlers as part of the config when you first plug autocomplete into the input.
Y.one("#ac").plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'phraseMatch',
source: ['foo', 'bar', 'baz'],
on : {
select : function(e) {
console.log(arguments); //TODO: REMOVE DEBUGGING
}
}
});
You can also subscribe after the element has been plugged using the namespace it attaches to ("ac").
Y.one("#ac").ac.on("select", function() {
console.log("post-plugin event subscription"); //TODO: REMOVE DEBUGGING
});
If you are using it as a class, it works like this.
var ac = new Y.AutoComplete({
inputNode: '#ac',
source: ['foo', 'bar', 'baz']
});
ac.on("select", function() {
console.log("Class event subscription"); //TODO: REMOVE DEBUGGING
});
这篇关于YUI自动完成事件,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!