3
我有一个选择2功能类似下面,选择2组选定的值设置为隐藏字段
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的更新另一个隐藏字段的值。 有没有办法做到这一点?
@RabNawaz有没有这样的一个事件。你是对的。这就是它在这个例子中被创建的原因。请检查一下。 – zeliboba 2013-05-07 11:31:31
在我的情况下不工作的哥们。 – Gagan 2017-09-14 14:56:54