0

我正在使用运行顺畅的 jQuery UI DataTables。

我有大约 20 个过滤选项。有些是下拉菜单,一些日期选择器和相当多的文本框。我想让这些文本框自动完成数据库中的数据。

一个星期以来,我一直在用它敲打我的头。

如果是的话,是否可以使用 DataTables 自动完成?

任何建议都可以挽救生命。

在此处输入图像描述

4

2 回答 2

0

试试这个..你使用 php,所以它会是这样的。

jQuery

$(document).ready(function() {

    var LocalityArray = [];
  //$.getJSON('../../database/country.json', { id: data.id }, function(response) {
    $.getJSON("locality.php", { getLocality: '495074' }, function(response) {
        // Here (response) is array format. Like this

        // [{"LocalityID":9397,"CityID":55,"LocalityName":"Adugodi"},{"LocalityID":9398,"CityID":55,"LocalityName":"Aga Abbas Ali Road"},{"LocalityID":9399,"CityID":55,"LocalityName":"Agaram"},{"LocalityID":9400,"CityID":55,"LocalityName":"Agrahara Dasara Halli"},{"LocalityID":9401,"CityID":55,"LocalityName":"Agrahara Dasarahalli"},{"LocalityID":9402,"CityID":55,"LocalityName":"Airport Exit Road"},{"LocalityID":9403,"CityID":55,"LocalityName":"Horamavu"},{"LocalityID":9404,"CityID":55,"LocalityName":"Hosakere Halli"},{"LocalityID":9405,"CityID":55,"LocalityName":"Hennur"},{"LocalityID":9406,"CityID":55,"LocalityName":"Hesaraghatta"},{"LocalityID":9407,"CityID":55,"LocalityName":"HKP Road"},{"LocalityID":9408,"CityID":55,"LocalityName":"HMT Layout"},{"LocalityID":9409,"CityID":55,"LocalityName":"Hongasandra"},{"LocalityID":9410,"CityID":55,"LocalityName":"Hoody"},{"LocalityID":9411,"CityID":55,"LocalityName":"Hayes Road"}    ]

        $.each(response, function(key, value) {
            LocalityArray[key] = value.LocalityName;
        });

        $(".txtLocality").autocomplete({
            minLength: 2,
            source: LocalityArray
        });
    }, 'json');

});

HTML

<table>
    <tr>
        <td>
            <input type="text" class="txtLocality" />
            <input type="text" class="txtLocality" />
            <input type="text" class="txtLocality" />
        </td>
    </tr>
</table>
于 2013-07-04T11:28:00.187 回答
0

我无法使用 DataTable 代码本身自动完成工作。

相反,我使用了一个名为Chosen的 jQuery 插件。它很好地达到了目的。它非常简单易用。

我希望它对其他人有帮助。

于 2014-04-24T12:30:03.757 回答