我使用Twitter Bootstrap和typeahead。Twitter引導-typeahead
我下載插件:Twitter的引導插件事先鍵入的內容擴展
等長這麼好,它的工作時,我使用的是靜態的JavaScript JSON數組如。
$('#demo1').typeahead({
source: [
{ id: 9000, name: 'Aalborg' },
{ id: 2, name: 'Montreal' },
{ id: 3, name: 'New York' },
{ id: 4, name: 'Buffalo' },
{ id: 5, name: 'Boston' },
{ id: 6, name: 'Columbus' },
{ id: 7, name: 'Dallas' },
{ id: 8, name: 'Vancouver' },
{ id: 9, name: 'Seattle' },
{ id: 10, name: 'Los Angeles' }
],
itemSelected: displayResult
});
當我嘗試使用AJAX它會做enerything,我的代碼看起來是這樣。
$('.typeahead').typeahead({
ajax: '/actions/search/synonymSearch',
itemSelected: displayResult
});
和返回該JSON數組(我可以在所有的方式重建其,我不能讓它的工作)
[
{ id: 1, name: 'Toronto' },
{ id: 2, name: 'Montreal' },
{ id: 3, name: 'New York' },
{ id: 4, name: 'Buffalo' },
{ id: 5, name: 'Boston' },
{ id: 6, name: 'Columbus' },
{ id: 7, name: 'Dallas' },
{ id: 8, name: 'Vancouver' },
{ id: 9, name: 'Seattle' },
{ id: 10, name: 'Los Angeles' }
]
插件主頁。 https://github.com/tcrosen/twitter-bootstrap-typeahead
我HOBE enybardy可以幫助我在這裏:)
非常感謝所有幫助,:)
編輯 - 問題resovle! :) 只需要將header("content-type: application/json");
添加到我的PHP文件中,hobe這個答案對於其他人來說是有用的! :)
我真的不明白你在做什麼。但是關於用戶選擇什麼東西的部分,因爲它會變成一個郵政編碼 - 這是您需要實現的功能,而不是鍵入控件的一部分。 –
我會盡力解釋,所以,:) – ParisNakitaKejser