0

これが私が戻ってきた応答です(動作しています):

{"matches":[
  {"_core_product_id":"648","finish":"Distressed Green\/Antique Bronze","COUNT(*)":"1"},
  {"_core_product_id":"157","finish":"Nightingale Green","COUNT(*)":"1"}],
"count":2}

ドロップダウン選択で各カテゴリカテゴリとCOUNT(*)を表示したい。すぐに必要というわけではありませんが、_core_product_id をオートコンプリート フィールド以外の別の場所で使用したいと考えています。

これが私のオートコンプリートjqueryコードです:

.autocomplete({
    source: function( request, response ) {
        $.getJSON( 'controllers/clean/ajax/search.php', {
            'fieldid_tableid_type' : this.element[0].id,
            'term': extractLast( request.term )
        //}, response(['red', 'green', 'blue']) );
        }, 
        response );
    },
    search: function() {
        // custom minLength
        var term = extractLast( this.value );
        if ( term.length < 2 ) {
            return false;
        }
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( '' );
        this.value = terms.join( '| ' );
        return false;
    },
    delay: 750
});

「応答」をどこに置くか、どのように使用するかがわかりません。どんな助けでも素晴らしいでしょう。これについて他にも (たくさん) 質問があることは知っていますが、私の問題を解決する質問はまだ見つかりません。ありがとう。

jquery ui のドキュメントには、応答がオートコンプリートのすぐ内側で使用されていることが示されていることに気付きました。一部の例では、他の場所を示しています (たとえば、ソースのすぐ内側)。jQuery UI ドキュメント: http://api.jqueryui.com/autocomplete/#event-response

4

1 に答える 1

0

これresponseは、リモートでロードされた値を渡す必要があるコールバック関数です。

.autocomplete({
    source: function( request, response ) {
        response($.getJSON( 'controllers/clean/ajax/search.php', {
            'fieldid_tableid_type' : this.element[0].id,
            'term': extractLast( request.term )
            //}, response(['red', 'green', 'blue']) );
        }));
    },
    search: function() {
        // custom minLength
        var term = extractLast( this.value );
        if ( term.length < 2 ) {
            return false;
        }
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function( event, ui ) {
        var terms = split( this.value );
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( '' );
        this.value = terms.join( '| ' );
        return false;
    },
    delay: 750
});
于 2013-05-04T04:30:33.573 に答える