Javascript 使用jquery ui自动完成但隐藏样式

Javascript 使用jquery ui自动完成但隐藏样式,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我使用jQueryUI自动完成并得到结果,这是我得到结果的唯一问题 不确定为什么不显示,json的json是正确的 我的JSOn [{"name":"author","type":"U","status":"0","owner":"dbo"},{"name":"author_dates","type":"U","status":"0","owner":"dbo"}] $("#student").autocomplete( { source: function(request

我使用jQueryUI自动完成并得到结果,这是我得到结果的唯一问题

不确定为什么不显示,json的
json
是正确的

我的JSOn

[{"name":"author","type":"U","status":"0","owner":"dbo"},{"name":"author_dates","type":"U","status":"0","owner":"dbo"}] 

$("#student").autocomplete(
    {
    source: function(request, response) {
    $.ajax({
        url: "search.cfc?method=searchByName&returnformat=json",
        dataType: "json",
        data: {
        search: request.term,
        maxRows: 10
    },
    success: function(data) {
      response($.map(data, function(item) {
         return { 
            label: item.label, value: item.label 
         };
      }));
    }
    })
    },
    select: function( event, ui ) {
        $('#submit').css("display", "block");
    }
});

您的对象属性是名称,而不是标签,所以您应该写名称而不是标签

$("#student").autocomplete(
{
source: function(request, response) {
$.ajax({
    url: "search.cfc?method=searchByName&returnformat=json",
    dataType: "json",
    data: {
    search: request.term,
    maxRows: 10
},
success: function(data) {
  response($.map(data, function(item) {
     return { 
        label: item.name, value: item.name
     };
  }));
}
})
},
select: function( event, ui ) {
    $('#submit').css("display", "block");
}

}))

您的对象属性是name,而不是label,所以您应该写name而不是label

$("#student").autocomplete(
{
source: function(request, response) {
$.ajax({
    url: "search.cfc?method=searchByName&returnformat=json",
    dataType: "json",
    data: {
    search: request.term,
    maxRows: 10
},
success: function(data) {
  response($.map(data, function(item) {
     return { 
        label: item.name, value: item.name
     };
  }));
}
})
},
select: function( event, ui ) {
    $('#submit').css("display", "block");
}

}))

< P>请考虑以下事项:

$("#student").autocomplete({
  source: function(request, response) {
    $.getJSON("search.cfc", {
      method: "searchByName",
      returnformat: "json",
      search: request.term,
      maxRows: 10
    }, function(data) {
      response($.map(data, (item) => {
        return $.extend(item, {
          label: item.name,
          value: item.name,
        });
      }));
    });
  },
  select: function(event, ui) {
    $('#submit').css("display", "block");
  }
});

请考虑以下事项:

$("#student").autocomplete({
  source: function(request, response) {
    $.getJSON("search.cfc", {
      method: "searchByName",
      returnformat: "json",
      search: request.term,
      maxRows: 10
    }, function(data) {
      response($.map(data, (item) => {
        return $.extend(item, {
          label: item.name,
          value: item.name,
        });
      }));
    });
  },
  select: function(event, ui) {
    $('#submit').css("display", "block");
  }
});

请提供JSFIDDLE,我怀疑您呈现的项目格式不正确。请提供一个最小的、可复制的示例:对于jquery ui,请参见editI,在JSON对象中不查看
标签
。我只看到
名称
类型
状态
所有者
。因此,您的
.map()
将创建大量空元素。因此,解决方法是什么请给出JSFIDDLE我怀疑您正在以错误的格式呈现项目。请提供一个最小的、可复制的示例:对于jquery ui,请参见editI,在JSON对象中不查看
标签
。我只看到
名称
类型
状态
所有者
。因此,您的
.map()
将创建大量空元素。那么解决方法是什么