开发者

Jquery autocomplete by categories not returning selected result

开发者 https://www.devze.com 2023-02-09 12:54 出处:网络
I\'m trying to get the resulting listbox value from the autocomplete with categories example, and I can\'t get it to work like the other examples.I must be doing something stupid.

I'm trying to get the resulting listbox value from the autocomplete with categories example, and I can't get it to work like the other examples. I must be doing something stupid.

    
    $.widget( "custom.catcomplete", $.ui.autocomplete, {
        _renderMenu: function( ul, items ) {
            var self = this,
                currentCategory = "";
            $.each( items, function( index, item ) {
                if ( item.category != currentC开发者_开发技巧ategory ) {
                    ul.append( "" + item.category + "" );
                    currentCategory = item.category;
                }
                self._renderItem( ul, item );
            });
        },
                /* I ADDED THIS */
        select: function(event, ui){

alert(ui.item.value); } }); $(function() { var data = [ { label: "anders", category: "" }, { label: "andreas", category: "" }, { label: "antal", category: "" }, { label: "annhhx10", category: "Products" }, { label: "annk K12", category: "Products" }, { label: "annttop C13", category: "Products" }, { label: "anders andersson", category: "People" }, { label: "andreas andersson", category: "People" }, { label: "andreas johnson", category: "People" } ];

$( "#search" ).catcomplete({ delay: 0, source: data }); }); </script>


I figured it out. I needed to put it here:

$("#search").catcomplete({
    delay: 0,
    source: data,
    select: function(event, ui){
    alert(ui.item.label);
    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号