我使用 Jeditable 和自动完成,但在提交时我需要传递 ID 而不是名称。
我使用以下代码:
var data = [
{ text: 'PC Service 1', id: '46' },
{ text: 'PC Service 2', id: '48' },
{ text: 'PC Service 3', id: '49' },
{ text: 'Serviciu 1', id: '47' }
];
jQuery.editable.addInputType('autocomplete', {
element: jQuery.editable.types.text.element,
plugin: function(settings, original) {
jQuery('input', this).autocomplete(data, {
dataType: 'json',
parse: function(data) {
return jQuery.map(data, function(item) {
return {
data: item,
value: item.id,
result: item.name
};
});
},
formatItem: function(item) {
return item.text;
}
}).result(function(event, item) {
console.log ("Item: " + item.id);
nameId = item.id;
});
}
});
jQuery(".editableFieldAutocomplete").editable("index.cgi?action=plugin", {
indicator: "<img src='/$instance/images/loaders/loader2.gif'>",
tooltip: "Editeaza",
type: "autocomplete",
event: "mouseover",
style: "inherit",
id: 'fieldId',
name: 'fieldValue',
submitdata: function ( value, settings ) {
var nameId = nameId;
console.log ("nameId: " + nameId);
return {
invoiceId: "$fact",
mode: "api",
sec: "updateInvoiceJeditable_fct",
nameId: nameId
};
},
style: 'display: inline',
autocomplete: {
minLength : 2,
data : [
{ label: "Aberdeen", value:"1"},
{ label: "Ada", value: "2"},
{ label: "Adamsville", value: "3"},
{ label: "Addyston", value: "3"},
{ label: "Adelphi", value: "3"},
{ label: "Adena", value: "3"},
{ label: "Adrian", value: "3"},
{ label: "Akron", value: "3"}
]
}
});