Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.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 显示模块模式未按预期工作_Javascript_Jquery_Jqgrid - Fatal编程技术网

Javascript 显示模块模式未按预期工作

Javascript 显示模块模式未按预期工作,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,所以我制作了一个小“jqgrid工厂”,这是我第一次从头开始编写一个揭示模块javascript diddy: var jqGridReportFactory = (function () { var config = { datatype: 'json', mtype: 'GET', height: 'auto', autowidth: true, shrinkToFit: true, g

所以我制作了一个小“jqgrid工厂”,这是我第一次从头开始编写一个揭示模块javascript diddy:

var jqGridReportFactory = (function () {

    var config = {
        datatype: 'json',
        mtype: 'GET',
        height: 'auto',
        autowidth: true,
        shrinkToFit: true,
        gridview: true,
        sortable: true,
        rowNum: 50,
        rowList: [50, 100, 200],
        viewrecords: true,
        loadonce: false,
        sortorder: 'asc',
        sortname: 'Affiliate',
        subGridSortname: 'SubAffiliate'
    },
    subGridOptions = {
        plusicon: "ui-icon-plus",
        minusicon: "ui-icon-minus",
        openicon: "ui-icon-carat-1-sw"
    },
    gridOptions = {
        id: null,
        pager: null,
        url: null,
        postData: null,
        colNames: null,
        colModel: null,
        pager: null,
        subGrid: false,
        subGridPostdata: null,
        subGridHeadersHidden: true
    };


    function createReport(gridOptions, optionalConfig) {
        $.extend(this.config, optionalConfig);
        $.extend(this.gridOptions, gridOptions);

        var jqGridObj = {
            url: this.url,
            datatype: this.config.datatype, //ERROR HERE!
            mtype: this.config.mtype,
            postData: this.gridOptions.postdata,
            colNames: this.gridOptions.colNames,
            colModel: this.gridOptions.colModel,
            height: this.config.height,
            autowidth: this.config.autowidth,
            shrinkToFit: this.config.shrinkToFit,
            gridview: this.config.gridview,
            sortable: this.config.sortable,
            rowNum: this.config.rownum,
            rowList: this.config.computeHighlightColorsrowList,
            viewrecords: this.config.viewrecords,
            loadonce: this.config.loadonce,
            sortorder: this.config.sortorder,
            sortname: this.gridOptions.sortname,
            pager: this.gridOptions.pager,
            loadError: function (xhr, st, err) {
                reportLoadError('onLoadConversionHistory', xhr, st, err);
                unblockUI();
            },
            gridComplete: function () {
                unblockUI();
                goToScrollPosition($('#reportPlaceHolder'));
            },
            subGrid: this.gridOptions.subGrid,
            subGridRowColapsed: function (subgrid_id, row_id) {
                // this function is called before removing the data 
                var subgrid_table_id;
                subgrid_table_id = subgrid_id + "_t"; //
                $("#" + subgrid_table_id).remove();
            },
            onSelectRow: function (rowid) {
                $(this).jqGrid("toggleSubGridRow", rowid);
            }
        };

        if (this.subGrid) {
            var subGridObj = {
                subGridOptions: this.subGridOptions,
                subGridRowExpanded: function (subgridId, rowId) {
                    var affiliate = $("#" + this.id).jqGrid("getCell", rowId, 'Affiliate');

                    var subgridTableId = subgridId + "_t";
                    var $subGrid;
                    $("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table>");
                    $subGrid = $('#' + subgridTableId); //cache subgrid, more performant

                    //change parent names from Affiliate to Subaffiliate
                    //other than that subGrid model is exactly the same as parent Affiliate model for all reports so far
                    this.gridOptions.colNames[0] = 'Subaffiliate';
                    this.gridOptions.colModel[0].name = 'SubAffiliate';
                    this.gridOptions.colModel[0].index = 'SubAffiliate';

                    //add affiliate to subGridPostData
                    var a = { Affiliate: affiliate };

                    $.extend(this.gridOptions.subGridPostdata, a)
                    $subGrid.jqGrid({
                        url: this.gridOptions.url,
                        datatype: this.gridOptions.datatype,
                        mtype: this.gridOptions.mtype,
                        postData: this.gridOptions.subGridPostdata,
                        colNames: this.gridOptions.colNames,
                        colModel: this.gridOptions.colModel,
                        height: this.config.height,
                        sortname: this.config.subGridSortname,
                        sortorder: this.config.subGridSortorder,
                        loadonce: this.config.loadonce,
                        //these subgrid setting should not be overridden in my opinion - Brian Ogden
                        autowidth: true,
                        shrinkToFit: true,
                        gridview: false,
                        sortable: false,
                        viewrecords: true
                        ///////////////////////
                    });

                    if (subGridHeadersHidden) {
                        //hide subgrid column headers
                        $subGrid.closest("div.ui-jqgrid-view")
                        .children("div.ui-jqgrid-hdiv")
                        .hide();
                    }
                },
            };

            $.extend(jqGridObj, subGridObj);
        }

        //jqGrid factory go!!
        $("#" + this.gridOptions.id).jqGrid(jqGridObj);
    }

    return {
        createReport: createReport
    };

})();

jqGridReportFactory.createReport(continuityGridOptions);
var jqGridReportFactory=(函数(){
变量配置={
数据类型:“json”,
mtype:'获取',
高度:“自动”,
自动宽度:正确,
shrinkToFit:是的,
gridview:没错,
可排序:是的,
rowNum:50,
行列表:[50100200],
viewrecords:是的,
loadonce:false,
排序器:“asc”,
sortname:“附属公司”,
subGridSortname:“子分支机构”
},
子网格选项={
普鲁西贡:“用户界面图标升级”,
小图标:“ui图标减号”,
openicon:“ui-icon-carat-1-sw”
},
网格选项={
id:null,
寻呼机:空,
url:null,
postData:null,
colNames:null,
colModel:null,
寻呼机:空,
子网格:false,
subGridPostdata:null,
subGridHeadersHidden:对
};
函数createReport(gridOptions,optionalConfig){
$.extend(this.config,optionalConfig);
$.extend(this.gridOptions,gridOptions);
var jqGridObj={
url:this.url,
datatype:this.config.datatype,//此处出错!
mtype:this.config.mtype,
postData:this.gridOptions.postData,
colNames:this.gridOptions.colNames,
colModel:this.gridOptions.colModel,
高度:this.config.height,
自动宽度:this.config.autowidth,
shrinkToFit:this.config.shrinkToFit,
gridview:this.config.gridview,
可排序:this.config.sortable,
rowNum:this.config.rowNum,
行列表:this.config.computeHighlightColorsrowList,
viewrecords:this.config.viewrecords,
loadonce:this.config.loadonce,
sortorder:this.config.sortorder,
sortname:this.gridOptions.sortname,
寻呼机:this.gridOptions.pager,
loadError:函数(xhr、st、err){
reportLoadError('onLoadConversionHistory',xhr,st,err);
unbui();
},
gridComplete:函数(){
unbui();
goToScrollPosition($(“#报告占位符”);
},
子网格:this.gridOptions.subGrid,
subGridRowColapsed:函数(子网格id,行id){
//在删除数据之前调用此函数
var子网格\u表\u id;
子网格\表\ id=子网格\ id+“\ t”//
$(“#”+子网格_表_id).remove();
},
OnSetRow:函数(rowid){
$(this).jqGrid(“toggleSubGridRow”,rowid);
}
};
if(此子网格){
var subGridObj={
subGridOptions:this.subGridOptions,
subGridRowExpanded:函数(subgridId,rowId){
var affiliate=$(“#”+this.id).jqGrid(“getCell”,rowId,“affiliate”);
var subgridTableId=subgridId+“\u t”;
var$子网格;
$(“#”+subgridId).html(“”);
$subGrid=$(“#”+subgridTableId);//缓存子网格,性能更高
//将父公司名称从附属公司更改为子附属公司
//除此之外,子网格模型与迄今为止所有报告的父关联模型完全相同
this.gridOptions.colNames[0]=“子分支机构”;
this.gridOptions.colModel[0]。名称='SubAffiliate';
this.gridOptions.colModel[0]。索引='SubAffiliate';
//将附属机构添加到subGridPostData
var a={附属公司:附属公司};
$.extend(this.gridOptions.subGridPostdata,a)
$subGrid.jqGrid({
url:this.gridOptions.url,
数据类型:this.gridOptions.datatype,
mtype:this.gridOptions.mtype,
postData:this.gridOptions.subGridPostdata,
colNames:this.gridOptions.colNames,
colModel:this.gridOptions.colModel,
高度:this.config.height,
sortname:this.config.subGridSortname,
sortorder:this.config.subGridSortorder,
loadonce:this.config.loadonce,
//在我看来,这些子网格设置不应该被覆盖-Brian Ogden
自动宽度:正确,
shrinkToFit:是的,
gridview:false,
可排序:false,
viewrecords:正确
///////////////////////
});
if(子网格标题隐藏){
//隐藏子网格列标题
$subGrid.closest(“div.ui-jqgrid-view”)
.儿童(“div.ui-jqgrid-hdiv”)
.hide();
}
},
};
$.extend(jqGridObj,subGridObj);
}
//jqGrid工厂开始!!
$(“#”+this.gridOptions.id).jqGrid(jqGridObj);
}
返回{
createReport:createReport
};
})();
jqGridReportFactory.createReport(continuityGridOptions);
获取错误:未捕获类型错误:无法读取未定义的属性“datatype”。我已经对上面代码中抛出的错误行进行了注释。
我认为此
有问题,因此我设置第一个显示模块模式的方式也有问题。

将行更改为:

datatype: config.datatype
您不需要
这个
,因为
config
变量在
createReport()中是完全可以访问的

this.url
不可用的原因