[英]JqGrid + Autocomplete
I'm having trouble implementing autocomplete in jqgrid. 我在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: 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}},
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. 旨在将参数更多地传递给javascript函数的目的是为了不对每个字段永远重复相同的函数,因为我需要不断更改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 很抱歉这个问题,但是我没有太多的JavaScript经验,所以我遇到了一些困难
First of all you don't need to use edittype : 'custom'
to be able to use jQuery UI Autocomplete. 首先,您无需使用edittype : 'custom'
即可使用jQuery UI Autocomplete。 Instead of that you can use just dataInit
. 取而代之的是,您可以只使用dataInit
。
You can define myAutocomplete
function for example like 您可以定义myAutocomplete
函数,例如
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);
}
and then use 然后使用
{ name:'COD_OBJ_EST', hidden: true, editable: true,
editoptions: {
dataInit: function (elem) {
myAutocomplete(elem, "autocomplete.php?id=estrategico");
}
}}
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. 请注意,将发送到服务器的参数名称是标准名称term
而不是您当前使用的名称q
。 I personally don't see any need to change the default name of the parameter. 我个人认为不需要更改参数的默认名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.