这是我的 jquery 代码,用于从本地源设置引导类型头
$(function () {
var src = [{ id: 1, name: 'Toronto', state: 'ON', country: 'Canada', key: 12345 },
{ id: 2, name: 'Montreal', state: 'QC', country: 'Canada', key: 23456 },
{ id: 3, name: 'New York', state: 'NY', country: 'USA', key: 34567 },
{ id: 4, name: 'Buffalo', state: 'NY', country: 'USA', key: 45678 },
{ id: 5, name: 'Boston', state: 'MA', country: 'USA', key: 56789 },
{ id: 6, name: 'Columbus', state: 'OH', country: 'USA', key: 67890 },
{ id: 7, name: 'Dallas', state: 'TX', country: 'USA', key: 78901 },
{ id: 8, name: 'Vancouver', state: 'BC', country: 'Canada', key: 89102 },
{ id: 9, name: 'Seattle', state: 'WA', country: 'USA', key: 90123 },
{ id: 10, name: 'Los Angeles', state: 'CA', country: 'USA', key: 11234}];
localStorage.setItem("cities", JSON.stringify(src));
$('#search').typeahead({
sources: [
{ name: "local", type: "localStorage", key: "cities" }
]
});
});
它工作正常。如何从服务器进行 ajax 调用并将如上所示的类似数据与源连接。
update
:
这是 jsfiddle 上的上述工作代码http://jsfiddle.net/MMarW/
这是 jsfiddle 上没有触发的 ajax 代码http://jsfiddle.net/FZP8a/3/