我在网格中有 3 个组合框:部门、员工和联系人。在部门变更时,将填充员工;但是在更换员工时,我无法获得联系。
jQuery().ready(function($) {
var deptIdToEmployeeArray = {
1: { '1': 'asish', '2': 'prem', '3': 'praba'},
2: { '4': 'ragow', '5': 'subbu','6': 'arthi'},
3: { '7': 'manoj', '8': 'vimalda' }
};
var empIdToContactArray = {
1: { '1': '9994782468', '2': '464590', '3': '254013'},
4: { '4': '7245684235', '5': '464591', '6': '365895'},
7: { '7': '8098756512', '8': '464592', '9': '314562'}
};
{
name : 'departmentId',
index : 'departmentId',
editable : true,
edittype : 'select',
formatter : 'select',
editoptions : {
value : "1:CG;2:IDE;3:.NET",
dataInit: function (elem) {
var v = $(elem).val();
jQuery("#StaticEG").setColProp('employeeId', {
editoptions: {
value: deptIdToEmployeeArray[v]
}
});
},
dataEvents: [{ //this triggers on change of department combo-box
type: 'change',
fn: function(e){
var employees = deptIdToEmployeeArray[this.value];
var employeeComboHtml = '';
for (var employee_id in employees) {
if (employees.hasOwnProperty(employee_id)) {
employeeComboHtml += '<option role="option" value="' + employee_id + '">' + employees[employee_id] + '</option>';
}
}
var row = $(e.target).closest('tr.jqgrow');
if(row[0] != null) {
$("select", row[0].children[3]).html(employeeComboHtml);
} else {
$("select#employeeId").html(employeeComboHtml);
}
},
{
name : 'employeeId',
index : 'employeeId',
editable : true,
edittype : 'select',
formatter : 'select',
editoptions : {
value : "",
dataInit: function (elem) {
var v = $(elem).val();
jQuery("#StaticEG").setColProp('contactId', {
editoptions: {
value: empIdToContactArray[v]
}
});
},
dataEvents: [{ //this DOES NOT triggers on change of employee combo-box
type: 'change',
fn: function(e){
var contacts = empIdToContactArray[this.value];
var contactCombo = '';
for (var contact_id in contacts) {
if (contacts.hasOwnProperty(contact_id)) {
contactCombo += '<option role="option" value="' + contact_id + '">' + contacts[contact_id] + '</option>';
}
}
var row = $(e.target).closest('tr.jqgrow');
$("select", row[0].children[4]).html(contactCombo);
}
}]
},
align : 'right',
search : true
}
{
name : 'contactId',
index : 'contactId',
editable : true,
edittype : 'select',
sortable : false,
editoptions : {
value : "",
},
align : 'right',
search : true
}
employeeId 中的第二个 dataEvents 不会在更改员工组合框时触发。为什么 ?我在这里做错了什么?