2013-06-27 42 views
0

任何人都可以建議我如何在子網格的自定義驗證功能中獲取父行ID?jqGrid:在子網格的自定義驗證功能中獲取父行號

這是我的代碼

subGrid: true, 
       subGridRowExpanded: function (subgrid_id, row_id) 
       { 

        var subgrid_table_id; 
        subgrid_table_id = subgrid_id+"_t"; 
        var subgrid_pager_id = subgrid_id+"_p"; 
        jQuery("#"+subgrid_id).html("<table id="+subgrid_table_id+" class=scroll></table><div id="+subgrid_pager_id+" ></div>"); 
        jQuery("#"+subgrid_table_id).jqGrid(
        { 
         url:"form_subgrid_ajax_296.php?id="+row_id+"&child_form_id=296", 
         editurl:"../ajax/common_subgrid_edit_296.php?form_id="+sub_grid_id+"&parent_id="+row_id, 
         datatype: "json", 

         colNames: ['ID','PESO'], 
         colModel: [{name:'id',index:'id',editable:false,hidden:true}, 
          {name:'peso', 
        index:'peso', 
        formoptions:{elmsuffix:''},editrules:{required:true,custom:true, custom_func:customNumberChk},editable:true, 
           hidden:false, 
           search:true, 
           editoptions: {size:80, maxlength: 1000} 
           }], 
         sortorder: "asc", 
         height: 300, 
         loadonce: false, 
         width: 500, 
         rowNum:10, 
         rowList:[10,20,50], 
         sortname: 'id', 
         sortorder: "asc", 
         cellEdit: false, 
         cellsubmit: "clientarray", 
         caption:"Child", 
         pager: subgrid_pager_id 
        }); 
        jQuery("#"+subgrid_table_id).jqGrid 
        (
        "navGrid", 
        "#"+subgrid_pager_id, 
        { 
         edit:true, 
         add:true, 
         del:true, 
         search:false 
        }, 
        { 
         width:780, 
         recreateForm:true 
        }, 
        { 
         width:780, 
         recreateForm:true 
        } 
       ); 
       } 

現在看名稱: '比索',指數: '比索',。我使用了自定義的功能customNumberChk。

這是我的自定義功能

function customNumberChk(value,colname) 
{ 

} 

我想在這個功能的rowid。

+0

這你使用的那種子網格? [Subgrid as Grid](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid_as_grid)? – Oleg

+0

是的,我使用的次網格作爲網格 – Napster

+0

的情況下,你有ROWID爲'subGridRowExpanded'回調的參數,我不完全明白你的問題。問題可能存在於你組織代碼的形式中。你應該包括你當前使用的代碼。 – Oleg

回答

0

只有在您定義用於自定義驗證的功能customNumberChk的地方纔重要。 JavaScript允許訪問外部範圍中定義的任何變量。一個名字,例如closure(更多信息請參見the answer)。所以,你可以例如定義customNumberChksubGridRowExpanded匿名回調函數內:

subGridRowExpanded: function (subgrid_id, row_id) { 
    var subgrid_table_id; 
    function customNumberChk (value, colname) { 
     // one can use here ANY variable from the outer scope 
     // inclusive subgrid_id, row_id, subgrid_table_id and so on 
    } 
    ... 
    jQuery("#"+subgrid_table_id).jqGrid({ 
     ... 
     colModel: [... 
      {name:'peso', 
      ... 
      editrules:{required:true,custom:true, custom_func: customNumberChk} 
      } 
     ... 
    }); 
    ... 
} 

以同樣的方式,你可以在任何沒有定義customNumberChk功能和使用custom_func定義爲匿名函數:

subGridRowExpanded: function (subgrid_id, row_id) { 
    var subgrid_table_id; 
    ... 
    jQuery("#"+subgrid_table_id).jqGrid({ 
     ... 
     colModel: [... 
      { 
       name:'peso', 
       ... 
       editrules: { 
        required: true, 
        custom: true, 
        custom_func: function (value, colname) { 
         // one can use here ANY variable from the outer scope 
         // inclusive subgrid_id, row_id, subgrid_table_id 
         // and so on 
        } 
       } 
      } 
     ... 
    }); 
    ... 
} 
相關問題