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 に答える