1

グリッドに部門、従業員、連絡先の 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 内の 2 番目の dataEvents は、employee コンボ ボックスの変更時にトリガーされません。なんで ?ここで何が間違っていますか?

4

1 に答える 1

0

あなたは答えを得たに違いありませんが、これは他の人のためのものです。

あなたのemployeeId行には、value : ""どれが空かがあるからです。上記のようなものがあるはずですvalue : "1:CG;2:IDE;3:.NET",

于 2014-05-28T13:34:56.813 に答える