Код: Выделить всё
$('.drpCustomer').select2({
ajax: {
url: '/Ajax/GetCustomers',
dataType: 'json',
processResults: function (data) {
return {
results: data.map(function (item) {
return {
id: item.customerID,
text: item.customerName,
contactNo: item.contactNo
};
})
};
},
error: function (jqXHR, textStatus, errorThrown) {
console.error('AJAX error: ', textStatus, errorThrown);
}
},
templateResult: function (data) {
if (!data.id) {
return data.text;
}
return $('' +
'' + data.text + '' +
'' + (data.contactNo ? data.contactNo :'') + '' +
'');
},
templateSelection: function (data) {
return $('' +
'' + data.text + '' +
'' + (data.contactNo ? data.contactNo : '') + '' +
'');
}
});
Код: Выделить всё
$('body').on('click', '.txtCustomerID, .txtCustomerName', function (e) {
e.preventDefault();
var id = $(this).parents('tr').find('.txtCustomerID').text();
var cname = $(this).parents('tr').find('.txtCustomerName').text();
var cmobile = $(this).parents('tr').find('.txtCustomerMobile').text();
var option = new Option(cname +" " +cmobile, id, true, true);//******* Notice here
$('.drpCustomer').html(option).trigger('change');
});
Я пробовал передать таблицу как текст в новой опции('...')
но отображается [объект объекта]
а также попробовал, как показано ниже
Код: Выделить всё
var option = new Option({ text: cname, contactNo :cmobile}, id, true, true);Подробнее здесь: https://stackoverflow.com/questions/791 ... ing-jquery
Мобильная версия