数组数据未在JQgrid上填充

时间:2015-03-30 18:22:21

标签: jquery arrays jqgrid

我对jquery非常新,我正在尝试执行一些与jqgrid相关的程序。

这是我的代码,

<head>

    <link rel="stylesheet" type="text/css" media="screen" href="http://trirand.com/blog/jqgrid/themes/redmond/jquery-ui-1.8.1.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="http://trirand.com/blog/jqgrid/themes/ui.jqgrid.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="http://trirand.com/blog/jqgrid/themes/ui.multiselect.css" />

    <script src="http://trirand.com/blog/jqgrid/js/jquery.layout.js" type="text/javascript"></script>
    <script src="http://trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
    <script type="text/javascript">
        $.jgrid.no_legacy_api = true;
        $.jgrid.useJSON = true;
    </script>
    <script src="http://trirand.com/blog/jqgrid/js/ui.multiselect.js" type="text/javascript"></script>
    <script src="http://trirand.com/blog/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script src="http://trirand.com/blog/jqgrid/js/jquery.tablednd.js" type="text/javascript"></script>
    <script src="http://trirand.com/blog/jqgrid/js/jquery.contextmenu.js" type="text/javascript"></script>
</head>

<table id="grid"></table>

=============================================== ======================

var fd= [];
var sd = new Array();

for (var i = 0; i < 10; i++) {
sd.push(48803, "DSK1", "", "02200220", "OPEN");
}

var ld=[sd];
alert(ld);

var data = ld;

jQuery("#grid").jqGrid({
    datatype: "local",
    height: 250,
    colNames: ['Inv No', 'Thingy', 'Blank', 'Number', 'Status'],
    colModel: [{
        name: 'id',
        index: 'id',
        width: 60,
        sorttype: "int"},
    {
        name: 'thingy',
        index: 'thingy',
        width: 90,
        sorttype: "date"},
    {
        name: 'blank',
        index: 'blank',
        width: 30},
    {
        name: 'number',
        index: 'number',
        width: 80,
        sorttype: "float"},
    {
        name: 'status',
        index: 'status',
        width: 80,
        sorttype: "float"}
                                                                ],
    multiselect: true,
    caption: "Stack Overflow Example"
});


var names = ["id", "thingy", "blank", "number", "status"];
var mydata = [];

for (var i = 0; i < data.length; i++) {
    mydata[i] = {};
    for (var j = 0; j < data[i].length; j++) {
        mydata[i][names[j]] = data[i][j];
    }
}

for (var i = 0; i <= mydata.length; i++) {
    jQuery("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}

实际上我尝试使用下面的静态数据上面的代码,它在我的网格上正确显示了10条记录。

var data = [[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"],[48803, "DSK1", "", "02200220", "OPEN"]];

但是当我以这种方式使用动态数组尝试相同时,我的网格上只有最后一条记录..

var fd = [];     var sd = new Array();

for (var i = 0; i < 10; i++) {
sd.push(48803, "DSK1", "", "02200220", "OPEN");
}

var ld=[sd];
alert(ld);

var data = ld;    

我在这里做的错误是什么,有人能帮忙吗?

0 个答案:

没有答案