我有一个如下所示的 select2 函数,
function select2AutocompleteManyToManyField(field, request_url){
var map = {};
$("#"+field).select2({
multiple: true,
placeholder: field,
minimumInputLength: 3,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: request_url,
dataType: 'json',
data: function (term) {
return {
query: term
};
},
results: function (data) { // parse the results into the format expected by Select2.
var objects = [];
$.each(data,function(i,obj){
map[obj.translations__name] = obj;
objects.push({
"text": obj.translations__name,
'id': map[obj.translations__name].id
});
});
return {results: objects};
}
}
});
}
我想用选定的字段 id 更新另一个隐藏字段的值。有没有办法做到这一点 ?