【发布时间】:2016-10-13 15:46:47
【问题描述】:
下面的exp为我工作,
$('#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'
);
我正在使用 Bootstrap 3 供您参考我刚刚将 tagsinput 重命名为 bstagsinput 因为 iIt 与其他 jquery 插件发生冲突。
请,有人帮我如何通过 ajax 动态显示建议吗? (我浪费了一整天的时间寻找解决方案,但对我没有任何用处。
【问题讨论】:
标签: jquery twitter-bootstrap-3 bootstrap-typeahead bootstrap-tags-input