Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqGrid-复选框未获取正确的输入值?_Javascript_Jquery_Jqgrid - Fatal编程技术网

Javascript jqGrid-复选框未获取正确的输入值?

Javascript jqGrid-复选框未获取正确的输入值?,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,下面是测试我的问题的示例代码。本地数组mydata,添加到网格中,最后一列带有复选框。您可以简单地复制并粘贴以立即运行它来查看我的问题 <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href="css/style.css"/> <link rel="stylesheet" type="text/css" href="css/ui-lig

下面是测试我的问题的示例代码。本地数组mydata,添加到网格中,最后一列带有复选框。您可以简单地复制并粘贴以立即运行它来查看我的问题

<!doctype html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.16.custom.css"/>
    <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/jquery-ui.js"></script>
    <script type="text/javascript" src="js/grid.locale-en.js" ></script>
    <script type="text/javascript" src="js/jquery.jqGrid.min.js" ></script>     
</head>
<body>
    <table id="list4"></table>

    <script type="text/javascript">
        jQuery("#list4").jqGrid({ 
        datatype: "local", 
        height: 250, 
        colNames:['Inv No', 'Client','Notes','Checked?' ], 
        colModel:[ 
        {name:'id',index:'id', width:60, sorttype:"int"}, 
        {name:'name',index:'name', width:100}, 
        {name:'note',index:'note', width:150, sortable:false}, 
        {name:'ind_checked',index:'ind_checked', width:100, sortable:false, align:'center', editable:true, 
            edittype:'checkbox', editoptions: { value:"Y:N" },  formatter:'checkbox'}
        ],
        caption: "Testing Check Option" }
        ); 
        var mydata = [ 
        {id:"1",name:"test1",note:"note1",ind_checked:"N"}, 
        {id:"2",name:"test2",note:"note2",ind_checked:"N"}, 
        {id:"3",name:"test3",note:"note3",ind_checked:"N"}, 
        {id:"4",name:"test4",note:"note4",ind_checked:"N"}, 
        {id:"5",name:"test5",note:"note5",ind_checked:"N"}, 
        {id:"6",name:"test6",note:"note6",ind_checked:"N"}, 
        {id:"7",name:"test7",note:"note7",ind_checked:"N"}, 
        {id:"8",name:"test8",note:"note8",ind_checked:"N"}, 
        {id:"9",name:"test9",note:"note9",ind_checked:"N"} ]
        ; 

        for(var i=0;i<=mydata.length;i++) {
            jQuery("#list4").jqGrid('addRowData',i+1,mydata[i]);
            var data = jQuery("#list4").jqGrid('getRowData',mydata[i].id);
            alert('Row ID:'+data.id+'; My data:'+mydata[i].ind_checked+'; Data stored in Grid:'+data.ind_checked);
        }
    </script>
</body>
</html>

jQuery(“#list4”).jqGrid({
数据类型:“本地”,
身高:250,
colNames:['Inv No'、'Client'、'Notes'、'Checked?'],
colModel:[
{名称:'id',索引:'id',宽度:60,排序类型:“int”},
{名称:'name',索引:'name',宽度:100},
{名称:'note',索引:'note',宽度:150,可排序:false},
{名称:'ind_checked',索引:'ind_checked',宽度:100,可排序:false,对齐:'center',可编辑:true,
edittype:'checkbox',editoptions:{value:'Y:N'},格式化程序:'checkbox'}
],
标题:“测试检查选项”}
); 
var mydata=[
{id:“1”,name:“test1”,note1,ind_checked:“N”},
{id:“2”,name:“test2”,note2,ind_checked:“N”},
{id:“3”,name:“test3”,note3,ind_checked:“N”},
{id:“4”,name:“test4”,note:“note4”,ind_checked:“N”},
{id:“5”,name:“test5”,note5,ind_checked:“N”},
{id:“6”,name:“test6”,note6,ind_checked:“N”},
{id:“7”,name:“test7”,note7,ind_checked:“N”},
{id:“8”,name:“test8”,note:“note8”,ind_checked:“N”},
{id:“9”,name:“test9”,note9,ind_checked:“N”}]
; 
对于(var i=0;i可能是,你可以试试这个

loadComplete: function (data) {
   var rowCount  = grid.getGridParam("reccount");
   if ( rowCount > 0 ) {
      for (var i = 0; i < data.rows.length; i++) {
          if (data.rows[i].cell[4] == 'Y') { // 4 cell ind_checked//
              $("tr#"+(data.rows[i].id)+".jqgrow > td > input.cbox:checked", grid[0]);
           }
      }
   }
}
loadComplete:函数(数据){
var rowCount=grid.getGridParam(“reccount”);
如果(行计数>0){
对于(var i=0;itd>input.cbox:checked”,网格[0]);
}
}
}
}
也许你可以试试这个

loadComplete: function (data) {
   var rowCount  = grid.getGridParam("reccount");
   if ( rowCount > 0 ) {
      for (var i = 0; i < data.rows.length; i++) {
          if (data.rows[i].cell[4] == 'Y') { // 4 cell ind_checked//
              $("tr#"+(data.rows[i].id)+".jqgrow > td > input.cbox:checked", grid[0]);
           }
      }
   }
}
loadComplete:函数(数据){
var rowCount=grid.getGridParam(“reccount”);
如果(行计数>0){
对于(var i=0;itd>input.cbox:checked”,网格[0]);
}
}
}
}

这里有一个替代解决方案来验证复选框是否被选中

function customFormatter(cellvalue, options, rowObject) {
    var checkBoxValue = "N" ;
    var cell = jQuery('#' + options.rowId + '_' + 'ind_checked');        
    var val = cell.prop("checked");

    if(val == true) {
        checkBoxValue = "Y";
    }
    return checkBoxValue;
}

这里有一个替代解决方案来验证复选框是否被选中

function customFormatter(cellvalue, options, rowObject) {
    var checkBoxValue = "N" ;
    var cell = jQuery('#' + options.rowId + '_' + 'ind_checked');        
    var val = cell.prop("checked");

    if(val == true) {
        checkBoxValue = "Y";
    }
    return checkBoxValue;
}

格式为复选框的列的接受值为(false | 0 | no | off | undefined),反之亦然。因此ind_checked:“N”应为ind|checked:“no”编辑选项仅在编辑模式下使用。有关信息:格式为复选框的列的接受值为(false | 0 | no | off | undefined),反之亦然。因此ind|checked:“N”应为ind|u checked:“no”编辑选项仅在编辑模式下使用。有关信息: