2013-10-01 18 views
1

我在網格中有3個組合框:部門,員工和聯繫人。 部門變更時,員工人數將會增加; 但是,員工的變化,我無法獲得聯繫人填充。jqgrid editoptions中的第二個dataEvents不觸發

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只是不會觸發員工組合框的更改。爲什麼? 我在這裏做錯了什麼?

+0

這是整個JavaScript?或者您只向我們展示了colModel屬性的相關片段? (另外,我想你注意到在最後兩個大括號分隔的塊之間有一個缺失的逗號。) –

回答

0

你必須得到答案,但這是其他。

因爲你的employeeId行,你有value : ""這是空的。應該有些東西在 以上,即value : "1:CG;2:IDE;3:.NET",

相關問題