如何搜索数据从json输入字段


How to search data from json in input field

我有一个json文件的url。在搜索输入框中输入pin码时,应显示pin码建议。

这是我的url,

https://data.gov.in/api/datastore/resource.json?resource_id=6176ee09 - 3 - d56 4 a3b - 8115 - 21841576 - b2f6& api key =。

请给我一些建议或建议。

您可以使用自动补全:

$(function () {
  $("#tags").autocomplete({
    source: function (request, response) {
      $.ajax({
        url: "https://data.gov.in/api/datastore/resource.json?resource_id=6176ee09-3d56-4a3b-8115-21841576b2f6&api-key=<app key>",
        dataType: "json",
        success: function (data) {
          response($.map(data.records, function (item) {
            if (item.pincode.indexOf($("#tags").val()) == 0)
              return {
                label: item.pincode, // built the label like you want
                value: item.pincode
              };
          }));
        }
      });
    }
  });
});
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div class="ui-widget">
    <label for="tags">Iincode: </label>
    <input id="tags">
</div>