0

基本的に、さまざまな結果の配列を返す PHP ファイルを取得しました (PHP は配列を送信し、正常に受信されます)。ここで、JQuery オートコンプリートで、他のフィールドではなく「名前」フィールドのみで検索し、結果を提案するときに「名前」フィールドのみを表示するようにします。しかし、一度選択すると、結果のすべての配列をページに入れたいと思います。

現在、提案された検索ですべての配列を取得し、HTML に「名前」のみを入れているすべてのものを表示しています。

私がしなければならないことは、JQにある変数をキャッチして、名前だけを検索することだと思います

誰でも私を助けてくれますか?ありがとうございます

PHP(作品)

                foreach ($this->get_charities() as $r){

                         $return = array (  'Name' => $r['Name'],
                                            'Contact' => $r['Contact'],
                                            'Postcode' => $r['Postcode'],
                                            'Phone' => $r['Phone'],
                                            'Fax' => $r['Fax'],
                                            'Website' => $r['Website'],                             
                                            'Email' => $r['Email'],
                                        );
                }

        return json_encode($return);    

JS

  <script>
        $(function() {
            function log( message ) {
                $( "<div>" ).text( message ).prependTo( "#log" );
                $( "#log" ).scrollTop( 0 );
            }

            $( "#birds" ).autocomplete({
                source: "search.php",
                minLength: 2,
                select: function( event, ui ) {
                    log( ui.item ?
                        "Selected: " + ui.item.value + " aka " + ui.item.id :
                        "Nothing selected, input was " + this.value );
                }
            });
        });
        </script>
4

1 に答える 1

0

以下のようにphpで配列を設定する必要があります

$return = array (  
    'value'=> $r['Name'],
    'label'=> $r['Name'],
    'Contact' => $r['Contact'],
    'Postcode' => $r['Postcode'],
    'Phone' => $r['Phone'],
    'Fax' => $r['Fax'],
    'Website' => $r['Website'],                             
    'Email' => $r['Email'],
);

これで、名前の値のみを検索してオートコンプリートし、カスタム値を選択関数に取得することもできます

$( "#birds" ).autocomplete({
    source: "search.php",
    minLength: 2,
    select: function( event, ui ) {
            alert(ui.item.Phone);   <-- here you can get all your custom values.
        alert(ui.item.Contact); <-- here you can get all your custom values.

        log( ui.item ?
            "Selected: " + ui.item.value + " aka " + ui.item.id :
            "Nothing selected, input was " + this.value );
    }
});
于 2012-10-09T09:42:12.680 に答える