Jquery Select2 Ajax +标签

时间:2015-02-02 15:38:25

标签: javascript jquery-select2

$("#nomlabo").select2({
    //tags:true,
    ajax: {
        dataType: "json",
        url: "includes/labotags.php",
        results: function (data) {
            //alert(data[1]);
            return {
                results: data
            };
        }
    },
    tags: ["result1", "result2", "result3", "result4"],
    maximumSelectionSize: 1
});
  

嗨我想将数据结果中的值放入“标签”中,   这怎么可行?

1 个答案:

答案 0 :(得分:0)

我已经改变了代码来从php而不是jquery:

$("#nomlabo").select2({
            tags: [
            <?php
            $results =array();
                if ($stm = $mysqli->prepare("SELECT * FROM laboratoire")) {
                        $stm->execute();
                        $stm->store_result();
                        $stm->bind_result($id,$nom_labo,$id_nationalite);
                        while ($stm->fetch()) {
                            echo '"'.$nom_labo.'",';
                        }
                    }
            ?>
            ],
            maximumSelectionSize: 1
        });