以下EXP引導標籤輸入建議,無法顯示與工作對我來說typehead與Ajax調用
$('#casecustomtag').bstagsinput({
typeahead: {
displayText: function (text) {
return text;
},
source: function (query, response) {
return ['Business and industry', 'Economics and finance', 'Education and skills', 'Employment, jobs and careers', 'Environment', 'Government, politics and public administration', 'Health, well-being and care', 'Housing', 'Information and communication', 'International affairs and defence', 'Leisure and culture', 'Life inthe community', 'People and organisations', 'Public order, justice and rights', 'Science, technology and innovation', 'Transport and infrastructure']
},
minLength: 2
},
addOnBlur: true,
freeInput: true,
confirmKeys: [13],
splitOn: null,
writerWidth: 'auto'
});
但是,當我嘗試了Ajax調用我無法看到的建議。不過,我的服務器得到了正確的迴應
$('#casecustomtag').bstagsinput({
typeahead: {
displayText: function (text) {
return text;
},
source: function (query, response) {
return $.get('/ajax/customtags/gettags', {
search: query,
userId: 1
}, function (data) {
console.log(data);
response = $.map(data.data, function (item) {
console.log(item.text);
return item.text;
});
return response;
}, 'json');
},
minLength: 2
},
addOnBlur: true,
freeInput: true,
confirmKeys: [13],
splitOn: null,
writerWidth: 'auto'
);
我使用引導3,供大家參考我剛剛改名tagsinput
到bstagsinput
爲IIT已與其他jQuery插件衝突。
請大家幫助我如何通過ajax動態顯示建議? (我浪費了整天搜索解決方案,但對我沒有用處
這給出錯誤「Uncaught TypeError:response is a function」 –