JqG​​rid + 自动完成

JqGrid + Autocomplete(JqG​​rid + 自动完成)
本文介绍了JqG​​rid + 自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jqgrid 中实现自动完成时遇到问题.我一直在研究,直到我将这个问题建立在一个目前不满足的网站上.问题是,在我正在开发的应用程序中,我必须多次使用自动完成功能.现在我有了这个功能:

I'm having trouble implementing autocomplete in jqgrid. I've walked researching, alias until I based this question on a site that currently do not meet. The problem is this, I have to use the autocomplete several times throughout the application I'm developing. And now I have this function:

Javascript:

Javascript:

function autocomplete_element(value, options) {
    var $ac = $('<input type="text"/>');
    $ac.val(value);
    $ac.autocomplete({
    source: function(request, response) 
    {        
        $.getJSON("autocomplete.php?id=estrategico",
            { q: request.term }, response);
    }
    });
    return $ac;
}

Jqgrid:

jQuery("#obj_oper_org").jqGrid({
    (...)
        {name:'COD_OBJ_EST',index:'COD_OBJ_EST', hidden: true, editable:true, editrules:{required:true, edithidden:true}, edittype : 'custom', editoptions : {'custom_element' : autocomplete_element}},

更多的目的是将参数传递给 javascript 函数,以免每个字段永远重复相同的函数,因为我需要不断更改 url.有没有可能制作出这种类型的东西?很抱歉这个问题,但我在 javascript 方面没有太多经验,所以我遇到了一些困难

What was intended to pass a parameter to the javascript function more in order not to repeat forever the same function for each field because I need to be constantly changing url. Is it possible to make something of the genre? Sorry for the question but I do not have much experience in javascript, so I have some difficulties

推荐答案

首先你不需要使用 edittype : 'custom' 就能使用 jQuery UI Autocomplete.取而代之的是,您可以只使用 dataInit.

First of all you don't need to use edittype : 'custom' to be able to use jQuery UI Autocomplete. Instead of that you can use just dataInit.

您可以定义 myAutocomplete 功能,例如像

You can define myAutocomplete function for example like

function myAutocomplete(elem, url) {
    setTimeout(function () {
        $(elem).autocomplete({
            source: url,
            minLength: 2,
            select: function (event, ui) {
                $(elem).val(ui.item.value);
                $(elem).trigger('change');
            }
        });
    }, 50);
}

然后使用

{ name:'COD_OBJ_EST', hidden: true, editable: true,
    editoptions: {
        dataInit: function (elem) {
            myAutocomplete(elem, "autocomplete.php?id=estrategico");
        }
    }}

请注意,将发送到服务器的参数名称是标准名称term,而不是您当前使用的名称q.我个人认为不需要更改参数的默认名称.

Be careful that the name of parameter which will be send to the server is the standard name term instead of the name q which you currently use. I personally don't see any need to change the default name of the parameter.

这篇关于JqG​​rid + 自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)