1

请您帮忙,如何使用 medoo 框架数据库自动填充 ajax + select2 以自动填充相同形式的另一个输入。这是我的ajax代码:

$('.matrix').select2({
    ajax: {
        url: "index.php",
        dataType: 'json',
        data: function (params,page) {
            return {
                q: params.term, // search term
                qa: 'matrix'
            };
        },
        processResults: function (data,params) {
            return {
                results: $.map(data, function(obj) {
                    return { id: obj.id, text: obj.text };
                })
            };
        },
        //cache: true,
    },
    minimumInputLength: 3,
    placeholder: "<?php _e('Please Select'); ?>",
});

请您指教。

4

1 回答 1

0

这是我的搜索数据:

case "matrix":
    $searchstring = "";
    if(isset($_GET['q'])) $searchstring = $_GET['q'];

    if($searchstring != "") {
        $items = $database->select("tbl_matrix", "*", [ "OR" => [
            "bc_name[~]" => $searchstring

        ]]);

    } else {
        $items = $database->select("tbl_matrix", "*");
    }

    $results = array();
    $results[0]['id'] = 0;
    $results[0]['text'] = __('None');


    $i = 1;
    foreach($items as $item) {
        $results[$i]['id'] = $item['id'];
        $results[$i]['text'] = $item['bc_code']." ".$item['bc_name'];
        $i++;
    }

    echo json_encode($results);
    break;
于 2018-08-09T15:57:09.313 回答