栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Typeahead&Bloodhound时如何在请求正文中发送数据?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Typeahead&Bloodhound时如何在请求正文中发送数据?

尝试使用typeahead.js

substringMatcher
函数
.on()
,,
input
事件的最小修改版本

var substringMatcher = function(strs, q, cb) {  return (function(q, cb, name) {    var matches, substrRegex;    // an array that will be populated with substring matches    matches = [];    // regex used to determine if a string contains the substring `q`    substrRegex = new RegExp(q, 'i');    // iterate through the pool of strings and for any string that    // contains the substring `q`, add it to the `matches` array    $.each(strs, function(i, str) {      if (substrRegex.test(str)) {        // the typeahead jQuery plugin expects suggestions to a        // Javascript object, refer to typeahead docs for more info        matches.push(name(str));      }    });    cb(matches);  }(q, cb, function(res) {    return res  }));};$("#typeahead").on("input", function(e) {  $.ajax({      url: "https://gist.githubusercontent.com/guest271314/"+ "ffac94353ab16f42160e/raw/"+ "aaee70a3e351f6c7bc00178eabb5970a02df87e9/states.json",      processdata:false,      data: JSON.stringify({        "search": "people",        "query": e.target.value      })    })    .then(function(json) {      if (e.target.value.length) {        substringMatcher(JSON.parse(json), e.target.value, function(results) {          $("#results ul").empty();          $.map(results, function(value, index) { $("#results ul") .append($("<li />", {   "class": "results-" + index,   "html": value }))          })        })      } else {        $("#results ul").empty();      }    }, function err(jqxhr, textStatus, errorThrown) {      console.log(textStatus, errorThrown)    })});<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><input type="text" id="typeahead" placeholder="search" /><br /><div id="results">  <ul>  </ul></div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418240.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号