简体   繁体   English

YUI3自动完成:选择事件后如何获取价值

[英]YUI3 Autocomplete: How to get value from after select event

I'm implementing application to obtain stock information from Yahoo Finance API using YUI3. 我正在实现使用YUI3从Yahoo Finance API获取股票信息的应用程序。 I've done the autocomplete list but face a problem on how to get the value after user click mouse or press enter on the list. 我已经完成了自动完成列表,但是在用户单击鼠标或在列表上按Enter键后,如何获取值面临一个问题。

Here is my code. 这是我的代码。 The problem is that mynode.after(...) gives an error but I have no idea why and how to fix it. 问题是mynode.after(...)给出了一个错误,但我不知道为什么以及如何解决它。 Any help would be appreciated. 任何帮助,将不胜感激。 Thank you. 谢谢。

   YUI().use('autocomplete', function (Y){
    mynode = Y.one('#comsymbol');
    mynode.plug(Y.Plugin.AutoComplete, {
        activateFirstItem: true,
        enableCache: false,
        source: function(query, callback) {
            $.ajax({
                dataType: "jsonp",
                cache: true,
                type: "GET",
                jsonp: "callback",
                jsonpCallback: "YAHOO.Finance.SymbolSuggest.ssCallback",
                data: {query:query},
                url: "http://autoc.finance.yahoo.com/autoc",
            });

            YAHOO.Finance.SymbolSuggest.ssCallback = function(data) {
                var result = data.ResultSet.Result;
                var lists = new Array();
                for( var i = 0; i < result.length; i++ ) {
                    var sb = result[i].symbol;
                    var nm = result[i].name;
                    var xch = result[i].exch;
                    var all = sb + ", " + nm + " (" + xch + ")";
                    lists[i] = all;
                }
                callback( lists );
            };
        },
        }

        mynode.after('select', function (e) {
            getStockInfo();
        });

    });

});

You must attach the event listener to the AutoComplete instance rather than the Node . 您必须将事件侦听器附加到AutoComplete实例而不是Node The AutoComplete instance can be accessed via the ac member of the Node , and from there you can simply attach your event callback as you had before: 可以通过Nodeac成员访问AutoComplete实例,从那里您可以像以前一样简单地附加事件回调:

mynode.ac.after('select', function (e) {
    getStockInfo();
});

Take a look at the YUI AutoComplete tutorial ( As a Plugin section specifically) for more details. 有关更多详细信息,请参见YUI自动完成教程 (专门作为“插件”部分)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM