我创建了一个网格,现在我正在尝试从xml加载网格数据和列。 我的列来自标头标签及其加载,但来自G标签的数据未加载。 代码:
initComponent: function() {
this.fields = [];
this.columns = [];
this.data = [];
Ext.Ajax.request({
url: 'XML/hart.xml',
scope: this,
timeout: global_constants.TIMEOUT,
method: "GET",
disableCaching: true,
failure: function(response) {
utils.showOKErrorMsg(sdisMsg.ajaxRequestFailed);
},
success: function(response) {
debugger;
var datas = response.responseXML;
Ext.each(datas.getElementsByTagName("HEADER"), function(header) {
this.buildField(header);
this.buildColumn(header);
}, this);
Ext.each(datas.getElementsByTagName("G"), function (columnData) {
this.fieldLength = this.fields.length;
this.record = [];
for (i = 0; i < this.fieldLength; i++) {
this.record.push(columnData);
}
this.data.push(this.record);
}, this);
this.store = new Ext.data.ArrayStore({
fields : this.fields
});
this.store.loadData(this.data);
}
});
buildField: function(header) {
this.fields.push({
name: header.getAttribute("DATAINDEX")
});
buildColumn: function(header) {
var hiddenflg = !(header.getAttribute("VISIBLE"));
if (header.getAttribute("VISIBLE") == "false")
hiddenflg = true;
var strHeaderName = '';
if ((Ext.isIE && !PC.common.isIE10()))
strHeaderName = header.text;
else
strHeaderName = header.textContent;
var strToolTip = "";
this.columns.push({
header: Ext.util.Format.htmlEncode(strHeaderName),
tooltip: strToolTip,
dataIndex: header.getAttribute("DATAINDEX"),
width: parseInt(header.getAttribute("LENGTH")),
metaID: header.getAttribute("M"),
enableHdMenu: false,
hidden: hiddenflg,
menuDisabled: true,
sortable: false,
scope: this,
/*renderer : function (value, metaData, record, rowIndex, colIndex, store){
debugger;
},*/
fixed: false,
expanded: true
});
},
}
网格代码: 在网格中我给了商店和专栏。
{xtype: 'panel',
title: "Search Result",
height:500,
items: [{
xtype: 'grid',
id: 'COHART_GRID',
autoHeight: true,
selType: 'checkboxmodel',
frame: true,
store: this.store,
autoHeight: true,
stripeRows: true,
columns: this.columns,
bbar: [{
xtype: 'button',
text: 'Exclude',
handler: function() {
debugger;
}
}, {
xtype: 'button',
text: 'Include',
handler: function() {
//debugger;
}
}]
}]
}
如果需要,我会发布我的xml。谢谢你的帮助。
答案 0 :(得分:1)
在buildField
函数中,您正确使用getAttribute来访问属性,但在this.record.push(columnData);
中您缺少它。
我认为想要一些符合
的内容this.record = [];
for (i = 0; i < this.fieldLength; i++) {
var fieldName = this.fields[i].name
this.record[fieldName] = columnData.getAttribute(fieldName);
}
未经测试且没有保修,但应该是关于它的。