나는 마지막 버전에서 Select2js를 사용합니다. 나는 문제에 직면 해있다. Ajax 데이터 소스를 사용하고 소스에서 데이터를 가져와야합니다.Select2js 아약스 소스에서 데이터 가져 오기
// call ajax for products
$('.product-select select').select2({
ajax: {
url: baseUrl +'/orders/get_products',
processResults: function (data) {
return {
results: data.items
};
},
select: function (data) {
// do nothing ...
console.log(data);
}
}
});
$('.product-select select').on('select2:select', function (evt) {
// try this but evt doesn't contain data
console.log(evt);
});
내 데이터 소스는 다음과 같습니다 : 나는 id_person 필드 I 행을 선택할 때마다 싶어
[{id: 3, text: 'test', id_person: 4}, {id: 5, text: 'oooo', id_person: 5}]
여기 내 코드입니다.
'CSTE 연구진 ('선택 2 : 선택'?, 기능 (EVT, 데이터) {/ * ... * /}'- 무엇은'data' – Tomalak
그것은'undefined'의 :( –
아, 괜찮아. [documentation] (https://select2.github.io/examples.html#events)는 선택된 데이터가'evt.data '안에 있음을 제안합니다. 그렇지 않은 경우 jsFiddle/stack snippet을 재현하십시오 문제가 생겼다. – Tomalak