问题描述
我有 2 个预先输入。根据第一个预先输入的值,我希望第二个预先输入自动加载它的列表。 showHintOnFocus 在我第一次聚焦第二个预先输入时起作用,但在第二个预先输入中进行选择后将不再起作用,即使删除了该值。
提前输入 1:
function regionTypeahead(selector,options) {
$(selector).typeahead({
source: function (request,response) {
if (options.data) {
options.data.name = request;
}
$('#SalesRepSearch').val(''); //This is the input for the second typeahead
$.ajax({
url: options.url || "/region/GetRegionsByName",type: options.type || "POST",dataType: options.dataType || "json",data: options.data || { name: request },success: options.success || function (data) {
var result = $.map(data,function (item) {
return {
name: item.name,id: item.id
};
});
response(result)
if (options.afterSuccess) {
options.afterSuccess(data)
}
}
})
},afterSelect: options.afterSelect || function (data) {
},messages: options.messages || {
noresults: "",results: ""
},items: options.items || 20,sorter: options.sorter || function (items) {
return items.sort(function (a,b) {
return (a.name < b.name ? -1 : 1)
});
}
});
}
提前输入 2:
function SalesRepTypeahead(selector,response) {
if (options.data) {
options.data.name = request;
}
var regionId = $('#RegionSearch').attr("data-regionid") || 0; //This is the input for the 1st typeahead
$.ajax({
url: options.url || "/SalesRepSearch/SalesRepSearchByNameAndRegionId",data: options.data || { searchKeyword: request,regionId: regionId },id: item.id,regionId: item.region.id,regionName: item.region.name
};
});
response(result)
if (options.afterSuccess) {
options.afterSuccess(data)
}
}
})
},afterSelect: options.afterSelect || function (data) {
},b) {
return (a.name < b.name ? -1 : 1)
});
},showHintOnFocus: true /*"all"*/ //Only works the first time the input gets focus and will not work after a selection has been made in this typeahead
});
}
此解决方案对我不起作用: https://github.com/bassjobsen/Bootstrap-3-Typeahead/issues/368#issuecomment-705743951。
这是 marcel 在 jsfiddle 上演示的类似场景: https://jsfiddle.net/aureole82/2dw5e6aj/
每次第二个预先输入获得焦点时,我该怎么做才能使 showHintOnFocus 触发?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)