以下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” –