jQuery AutoComplete插件 - minLength不起作用

时间:2013-04-21 17:49:58

标签: javascript jquery datatables jquery-autocomplete

自动完成工作正常,但它显示带有1个字符的自动提示框,我想更改它以仅在输入为> = 3时显示自动提示框。

我一直试图插入minLength'选项,但它没有采取任何措施。

我试图将第六行修改为:

.autocomplete(conf.opts, minLength: 3 || {});


但没有成功。


这是我的JS档案:

var myEditor;
// AutoComplete FieldType
$.fn.dataTable.Editor.fieldTypes.autoComplete = $.extend(true, {}, $.fn.dataTable.Editor.models.fieldType, {
    "create": function (conf) {
        conf._input = $('<input type="text" id="' + conf.id + '">')
        .autocomplete(conf.opts || {});

        return conf._input[0];
    },

    "get": function (conf) {
        return conf._input.val();
    },

    "set": function (conf, val) {
        conf._input.val(val);
    },

    "enable": function (conf) {
        conf._input.autocomplete('enable');
    },

    "disable": function (conf) {
        conf._input.autocomplete('disable');
    },

    // Non-standard Editor method - custom to this plug-in
    "node": function (conf) {
        return conf._input;
    }
});


$(document).ready(function () {
    myEditor = new $.fn.dataTable.Editor({
        "ajaxUrl": "./php/pTreinamentos.php",
        "domTable": "#example",
        "fields": [{
            "label": "Tema",
            "name": "tema",
            "type": "autoComplete",
            "opts": {
            "source": ['banana']
            }
        }
        ]
    });


    // DataTable
    var oTable = $('#example').dataTable({
        "sDom": "<'row-fluid'<'span6'T><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sAjaxSource": "./php/pTreinamentos.php",
        "bFilter": true,
        "bAutoWidth": false,
        "iDisplayLength": 20,
        "aoColumns": [{
            "mData": "tema"
            }
        ],
        "oTableTools": {
            "sSwfPath": "../../TableTools/media/swf/copy_csv_xls_pdf.swf",
            "sRowSelect": "single",
            "sPaginationType": "bootstrap",
            "aButtons": [{
                "sExtends": "editor_create",
                "editor": myEditor
                }, {
                "sExtends": "editor_edit",
                "editor": myEditor
                }, {
                "sExtends": "editor_remove",
                "editor": myEditor
                }
            ]
        }
    });

});

1 个答案:

答案 0 :(得分:1)

解决方案是在字段结构中添加选项。

"fields": [{
    "label": "Data",
    "name": "data",
    "type": "autoComplete",
    "opts": {
    "source": ['banana'],
    "minLength": 3
    }