0

私は本当にselect2とタグモードに固執しました。ユーザーがデータをタグとして入力できるようにしたい。「 」と「,」で区切ります。問題ない。私はこれを持っています。

ここで、すでに使用可能なタグを php ファイルで収集したいと考えています。私はすでにグーグルとここからいくつかのスニペットを試しました。php ファイルは json_encode を返します。誰かが私が間違っていることを見ていますか?

コードは次のとおりです。

  if($('#s2_tag_handler_receipient').length) {
            $('#s2_tag_handler_receipient').select2({

        tags: true,
        tokenSeparators: [",", " "],
        createSearchChoice: function (term, data) {

            if ($(data).filter(function () {
                return this.text.localeCompare(term) === 0;
            }).length === 0) {
                return {
                    id: term,
                    text: term
                };
            }
        },
        multiple: true,
        ajax: {
            url: "imapMailBox/autoCompleteReceipientsJson.php",
            dataType: "json",
            data: function (term, page) {
                return {
                    q: term
                };
            },
            results: function (data, page) {
                return {
                    results: data
                };
            }
        }       
            });
        }

これはphpファイルです:

<?php 
    $return[]=array('Paul','NotPaul');
    echo json_encode($return);
?>
4

1 に答える 1