2

我目前正在扩展 jQuery UI 小部件,如下所示:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });
    }    
});

这很好用,但我现在想扩展另一个函数,如下所示:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });
    }

    _response: function(contents){
        $.ui.autocomplete.prototype._response.apply(this, arguments);
        $(this.element).trigger("autocompletesearchcomplete", [contents]);
    }

});

不幸的是,这个错误,如上所示扩展多个功能的正确方法是什么?

谢谢

4

1 回答 1

2

我认为缺少逗号

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });

    }, // <--- you're missing this comma

    _response: function(contents){
        $.ui.autocomplete.prototype._response.apply(this, arguments);
        $(this.element).trigger("autocompletesearchcomplete", [contents]);
    }

});
于 2012-08-21T00:42:24.140 回答