I wrote a class, DataGridPane
, extended from a ContentPane
which holds a data grid. I have the following problems:
- In dojo's
request.post.then
function, thethis.xxx
property variables are not recognized and show asundefined
. Why is this happening? - The table doesn't display the data until I drag a split line into the page.
define([
'dojo/_base/declare',
'dijit/layout/ContentPane',
'dojo/dom-construct',
'dojo/_base/lang',
'dojo/store/Memory',
'gridx/Grid',
'gridx/core/model/cache/Sync',
'dojo/request',
'dijit/Tooltip',
'dojo/domReady!'
], function (
declare,
ContentPane,
DomConstruct, lang, Store, Grid, Cache, request, Tooltip) {
DataGridPane = declare('DataGridPane', ContentPane, {
id: "id",
title: undefined,
url: undefined,
requestType: "json",
gridContainer: undefined,
layout: undefined,
constructor:
function(params) {
//......
},
start: function() {
this.gridContainer = DomConstruct.create("div",{
id: "gridDiv"
}, this.domNode);
this.createGrid();
},
createGrid:
function() {
//Q1:I have to save this.layout to another variable, as the following
//code in request.post.then didn't see all this.xxx variables
var layout = this.layout;
request.post( this.url, { //Q1:this.url is OK
handleAs: this.urlType //Q1:this.urlType is OK
}
).then(
// Q1:console.log print 3 'undefined'
console.log( this.url + this.urlType + this.layout);
function(response){
var datalist = [];
var length = 0;
dojo.forEach(response.items, function(thisText, i){
datalist.push(lang.mixin({ id: i+1 }, thisText));
length++;
});
var store = new Store({
data: datalist
});
var grid = new Grid({
cacheClass: Cache,
store: store,
structure: layout
}, 'gridDiv');
grid.startup();
}, function(error){
console.log("An error occurred: " + error);
}
);
}
.......
});
//Return the DataGridPane object.
return DataGridPane;
});
Question 2 is about the response. I made the response the format below:
{
"items":[...],
"status":[...],
"description":[...]
}
response.items
hold the list to be show in the table cells; response.status
and response.description
carry 2 other lists I will use in tool tip. I include these 3 lists in one response instead of sending 3 separate requests to enhance efficiency. However, the table doesn't show anything when the page is loaded. The items in response.items
only become visible once I have dragged the split line.
As an experiment, I used a simpler format of the response as follows:
{
"items":[...]
}
When items
is the only element in the response, the items in response.items
are displayed when the page is opened, but I'll fail to retrieve enough data for one request. Isn't the dojo request designed to parse the complicated response?
I have tried a call to this.resize()
after grid.startup()
but it appears to have no effect.