English 中文(简体)
添加过滤器/研究,以动态方式从当地json档案中填充
原标题:Add filter/search to dropdown menu dynamically filled from a local json file

I m 寻求一种途径,将过滤器/研究添加到由当地json案卷动态填满的下台菜单。

我的发言稿:

var json = [{
    "id": 3,
    "name": "Ann"
  },
  {
    "id": 4,
    "name": "Karl"
  },
  {
    "id": 31,
    "name": "Jess"
  }
]

$(document).ready(function() {
  for (i in json) {
    $("#name-selector").append( <option id= "name-data" name="submit" type="submit" value="  + json[i]["name"] +  ">  + json[i]["name"] +  </option> );
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<div class="div-selectors">
  <h5>Name</h5>
  <form>
    <select value="false" name="name" id="name-selector" class="selectors">
      <option value="">Select option</option>
    </select>
  </form>
</div>

我试图在下降的菜单中增加一个投入选择,把投入放在下降的菜单之外。

我如何落实这一想法?

问题回答

你不能在当地将JSON档案存放在客户身上。 JSON文档应当存放在服务器上。 它想像你正在使用j Query,因此,我会利用AJAX将JSON文件写给服务器或从服务器读。

这里的一个例子是,通过你必须写的PHP文字阅读JSON案。 Research AJAX examples.

$.ajax({
  url: "get_json_options.php",
  type:  post ,
  data:   ,
  dataType: "json",
  async: true,
  //contentType: false,
  //cache: false,
  //processData: false,
  beforeSend: function() {
    //alert("before");
  },
  success: function(options) {
    console.log(options);
  },
  error: function(xhr, status, error) {
    console.log("Error in get_json_options.php:" + xhr.responseText);
  }
}); //ajax




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签