Так что я сделал немного «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);
Getting ошибки: Uncaught TypeError: не может прочитать свойство 'datatype' неопределенного. Я прокомментировал строку, в которой ошибка вызывается в приведенном выше коде. Что-то не так с this
Я верю и, следовательно, что-то не так с тем, как я установил свой первый раскрывающий модуль.
Так как же это не то, что я ожидаю, это не так = jqGridReportFactory? –
@BrianOgden 'this' более или менее равно' {createReport: createReport}; '- объект, который вы возвращаете. – ComFreek
Вижу, спасибо. Так что ничего не выглядит фанки с моей демонстрацией реализации шаблона модуля? –