YUI AutoComplete events, how to?

醉酒当歌 提交于 2019-12-21 11:05:13

问题


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?


回答1:


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
});


来源:https://stackoverflow.com/questions/4713987/yui-autocomplete-events-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!