使用 jquery-typeahead 仅使用键值对中的值进行搜索
Search using only values from key-value pair with jquery-typeahead
我正在使用 jquery-typeahead,我的 json 如下所示:
{
field_111: "Some text",
field_123: "Example text 2",
field_134: "Text 123"
}
当用户键入内容时,我希望显示值并且键将是一个隐藏字段。
我似乎只能拥有已知密钥或 non-key/value 对数组。
下面的代码是一个开始,但不会显示数据源中的值。
$('.testinput').typeahead({
order: "desc",
limit: 5,
hint: true,
highlight: true,
minLength: 1,
autocomplete: "on",
cancelButton: true,
source: {
data: [{
field_111: "Some text",
field_123: "Example text 2",
field_134: "Text 123"
}]
},
callback: {
onInit: function(node) {
console.log('Typeahead Initiated on ' + node.selector);
},
onSearch: function (node, form, item, event) {
console.log(item);
}
}
});
我创建了一个函数来更改 typeahead 支持的 json 结构,如下所示:
$.each(oldJsonStructure, function(key, value) {
newJsonStructure.push({ id:key, name:value });
});
我用以下内容更改了预输入选项以显示 ID 和名称字段:
$('.testinput').typeahead({
order: "desc",
limit: 5,
hint: true,
highlight: true,
minLength: 1,
autocomplete: "on",
cancelButton: true,
display: ['id', 'name']
source: {
newJsonStructure
},
callback: {
onSearch: function (node, form, item, event) {
console.log(item);
}
}
});
我正在使用 jquery-typeahead,我的 json 如下所示:
{
field_111: "Some text",
field_123: "Example text 2",
field_134: "Text 123"
}
当用户键入内容时,我希望显示值并且键将是一个隐藏字段。 我似乎只能拥有已知密钥或 non-key/value 对数组。 下面的代码是一个开始,但不会显示数据源中的值。
$('.testinput').typeahead({
order: "desc",
limit: 5,
hint: true,
highlight: true,
minLength: 1,
autocomplete: "on",
cancelButton: true,
source: {
data: [{
field_111: "Some text",
field_123: "Example text 2",
field_134: "Text 123"
}]
},
callback: {
onInit: function(node) {
console.log('Typeahead Initiated on ' + node.selector);
},
onSearch: function (node, form, item, event) {
console.log(item);
}
}
});
我创建了一个函数来更改 typeahead 支持的 json 结构,如下所示:
$.each(oldJsonStructure, function(key, value) {
newJsonStructure.push({ id:key, name:value });
});
我用以下内容更改了预输入选项以显示 ID 和名称字段:
$('.testinput').typeahead({
order: "desc",
limit: 5,
hint: true,
highlight: true,
minLength: 1,
autocomplete: "on",
cancelButton: true,
display: ['id', 'name']
source: {
newJsonStructure
},
callback: {
onSearch: function (node, form, item, event) {
console.log(item);
}
}
});