将超链接(href)添加到自动完成功能,我使用Materialize CSS

时间:2019-02-22 22:52:06

标签: javascript jquery ajax materialize

指导我执行此代码,在每个建议的示例(href =“ http://127.0.0.1:8000/usa/”)上,我都具有Materializecss的自动完成功能或带有超链接(href)的自动建议文本框。 谢谢

[
        {
            "id": 1,
            "title": "usa",
            "text": "coucou",
            "slug": "usa"
        }
]

<div class="input-field">
    <input type="text" id="autocomplete-input" class="autocomplete">
    <label for="autocomplete-input">Autocomplete</label>
</div>

$(document).ready(function() {
  $(function() {
    $.ajax({
      type: 'GET',
      url: 'http://127.0.0.1:8000/',
      success: function(response) {
        var countryArray = response;
        var countryList = {};
        for (var i = 0; i < countryArray.length; i++) {
          countryList[countryArray[i].title] = countryArray[i].null;
        }
        $('input.autocomplete').autocomplete({
          data: countryList,
           limit: 5,
           minLength: 3
        });
      }
    });
  });
});

0 个答案:

没有答案