如何将 JSON 多维数组转换为 javascript 自动完成列表的函数以及如何将选定的列表数组值分配给输入类型

How to convert JSON multidimentional array to javascript function for autocomplete list and how to assign selected list array values to input type

我使用以下代码获取自动完成列表。但是我想将选定列表的其他数组值分配给输入类型。

$(document).ready(function()
{
    $(function () {
        var getData = function(request, response) {
        $.get(
            "autocomplete_locality1.php?callback=?&term=" + request.term,
            function(data) {
        data1 = jQuery.parseJSON(data);
        var res=[];
        for(var i in data1){
          if(data1.hasOwnProperty(i)){
            res.push(data1[i]['value']);
          }
        }
        response(res);
            });
    };
 
    $("#locality").autocomplete({
    minLength: 1,
    source: getData,
    focus: function(event, ui) {
        $("#locality").val(ui.item.label);
        return false;
    },
    select: function(event, ui) {
        $( "#locality" ).val(ui.item.label);
        $("#city").val(ui.item.city);
        $( "#ptype").val(ui.item.ptype);
        $( "#rcl").val(ui.item.rcl);
        return false;
    }
})
.data("autocomplete")._renderItem = function(ul, item) {
    return $("<li></li>")
        .data("item.autocomplete", item )
        .append("<table><tr><td>" + item.label + "</td></tr></table>")
        .appendTo(ul);
};
    
});
    
});

我从“autocomplete_locality1.php”得到以下输出 [{"value":"Aher","label":"Aher","city":"Pune","rcl":"R","ptype":"Residential"},{"value":"Akruti ,"label":"阿克鲁蒂","city":"浦那","rcl":"L","ptype":"土地"}]

$(document).ready(function()
{
    $(function () {
    var getData = function(request, response) {
        $.get(
            "autocomplete_locality1.php?callback=?&term=" + request.term,
            function(data) {
        data1 = jQuery.parseJSON(data);
        var res=[];
        for(var i in data1){
          if(data1.hasOwnProperty(i)){
            res.push({rcl:data1[i]['rcl'], value:data1[i]['value'], label:data1[i]['label'], ptype:data1[i]['ptype'], city:data1[i]['city']});
          }
        }
                
        response(res);
            });
    };
 
    $("#locality").autocomplete({
    minLength: 1,
    source: getData,
    select: function(event, ui) {
        $("#locality").val(ui.item.value);
        $("#rcl").val(ui.item.rcl);
        $("#city").val(ui.item.city);
        $("#ptype").val(ui.item.ptype);
        return false;
    }
})
.data("ui-autocomplete")._renderItem = function(ul, item) {
        return $('<li title = "' + item.value + '">' + item.value + '</li>').appendTo(ul); 
};
    
});
    
});