YUI自动完成的活动,怎么样? [英] YUI AutoComplete events, how to?

查看:99
本文介绍了YUI自动完成的活动,怎么样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用YUI 3.3.0和自动完成小部件。我是全新的,以YUI。事情是这样的。我有自动完成的工作。

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?

推荐答案

下面是该插件的做法为例,<一个href=\"http://tivac.com/yui3/so/skladjfyhafjk_autocomplete.htm\">http://tivac.com/yui3/so/skladjfyhafjk_autocomplete.htm

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

您也可以订阅该元素已经用它连接到命名空间插入后(AC)。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆