【发布时间】:2016-06-22 23:34:51
【问题描述】:
我正在使用这个插件来实现 ajax 自动完成功能 https://github.com/bassjobsen/Bootstrap-3-Typeahead bootstrap-3 类型。下面的代码有效,但我不知道它为什么有效。具体来说 process 和 response 参数是如何工作的。
$(document).ready(function() {
$('#typeahead-input').typeahead({
autoSelect: true,
minLength: 1,
delay: 400,
source: function (query, process) {
$.ajax({
url: '/api/location',
data: {sstr: query},
dataType: 'json'
})
.done(function(response) {
// console.log(response)
return process(response);
});
}
});
});
我的 json 看起来像这样
[
{
"id": "123",
"name": "Frederiksted",
"state": "VI",
"zip_code": "840"
}
]
如果我想根据 zip_code 字段自动完成填充怎么办? 我试过做“response.zipcode”,但结果是未定义的
【问题讨论】:
标签: javascript jquery ajax twitter-bootstrap bootstrap-typeahead