问题描述
我正在实现 jquery 的 typeahead 并且在响应中传递 ajax 响应时遇到问题。
我尝试了很多,但都失败了。
这是代码。
// search form typeahead
var findData = function () {
return function findMatches(q,cb) {
$.get("http://127.0.0.1:8000/api/v1/fun-search/",(data,status) => {
console.log(data.dataArray)
cb(data.dataArray);
});
};
};
$('#the-basics .typeahead').typeahead({
hint: true,highlight: true,minLength: 1
},{
name: 'items',source: findData()
});
但是我在没有像下面这样的ajax调用的情况下工作得很好:
// search form typeahead
var findData = function () {
var items = ['Armchair','Sofa'];
return function findMatches(q,cb) {
cb(items);
};
};
$('#the-basics .typeahead').typeahead({
hint: true,source: findData()
});
我在这上面浪费了 5 天时间并没有解决。谁能告诉我的 ajax 数据不起作用的确切原因是什么?我尝试了很多不同的方法,但都失败了。
API 运行良好,响应数组现在与虚拟项目数组相同,但它不起作用。
谁能告诉我那里发生了什么确切的问题?
我正在使用以下 tyeahead 版本。
/*!
* typeahead.js 0.11.1
* https://github.com/twitter/typeahead.js
* copyright 2013-2015 Twitter,Inc. and other contributors; Licensed MIT
*/
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)