jQueryUI-使用json文件自动完成 [英] jQueryUI - Autocomplete with json file

查看:89
本文介绍了jQueryUI-使用json文件自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用json文件进行自动填充,但是当我在输入字段中键入内容时,它什么也没显示.我只想显示指定为"descricao"的数据,而不显示为"codigo"的数据.这是我的代码:

I'm trying to make an autocomplete using a json file but when I type on the input field, it shows nothing. I want to show only the data specified into "descricao", not into "codigo". Here is my code:

$(function() {
$('#autocompleteGrupo').autocomplete({
    source: function (request, response) {
        $.ajax({
            url: "jsonGrupo.jsp",
            dataType: 'json',
            data: request,
            success: function( data ) {
                response( $.map( data, function( item ) {
                    return {
                        label: value,
                        value: item.descricao
                    };
                }));
            }
        }); 
    },  
    minLength: 2
});
});

我的json文件:

[{"codigo":"1","descricao":"Tecnologia da Informação"}] 

谢谢

卢卡斯.

推荐答案

尝试下面显示的代码:


$(function() {
$('#autocompleteGrupo').autocomplete({
source: function (request, response) {
    $.ajax({
        url: "jsonGrupo.jsp",
        dataType: 'json',
        data: request,
        success: function( data ) {
            response( $.map( data, function( item ) {
                return(item.descricao)
            }));
        }
    }); 
   },  
   minLength: 2
  });
});


还要检查是否包含jquery ui js,css ..........


Also check that jquery ui js,css are included or not..........

这篇关于jQueryUI-使用json文件自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆