Cam*_*ron 5 jquery bootstrap-typeahead
我正在使用Bootstrap Typeahead插件,如下所示:
$('#Organisation').typeahead({
source: function (query, process) {
return $.get(AppURL + 'Organisations/Manage/SearchByName/',
{
term: query
},
function (data) {
var results = [];
var fullResults = [];
$.each(data, function (index, item) {
results.push(item.label);
fullResults.push({
id: item.ID,
label: item.label
});
});
return process(results);
});
},
updater: function (selection) {
$('#OrganisationID').val(selection);
}
});
Run Code Online (Sandbox Code Playgroud)
我有两个返回的数组,这是因为Typeahead只需要一个字符串列表而不是一个对象.第二个数组包含label和id.
一旦用户从列表中选择一个项目,我需要从该选择中获取ID,然后使用它插入隐藏字段.但选择将只是名称,因为ID不能通过Typeahead传递.
关于如何解决这个问题的任何想法?
两个返回数组的示例:
结果: ["Organisation 1","Organisation 2"]
fullResults: [{"label":"Organisation 1","ID":2},{"label":"Organisation 2","ID":1}]
| 归档时间: |
|
| 查看次数: |
21336 次 |
| 最近记录: |