我在网格中有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中的第二个dataEvent在更改员工组合框时不会触发。为什么? 我在这做错了什么?
答案 0 :(得分:0)
您必须得到答案,但这是针对其他人的。因为在employeeId
行中,您的value : ""
为空。应该有类似的东西
即value : "1:CG;2:IDE;3:.NET",