justmonkey
24 Apr 2007, 3:43 AM
I use MemoryProxy to load local jsondata, but there is no results in grid.
/*myconfig.js*/
var MyConditionConfig = function () {
var req, unConfigedStore, configedStore, columnModel, unConfigedGrid, configedGrid ;
return {
init : function() {
columnModel = new Ext.grid.ColumnModel([{
header: "Name",
dataIndex: 'name',
width: 100
}, {
header: "Type",
dataIndex: 'type',
width: 50
}]);
req = new ActiveXObject("Msxml2.XMLHTTP");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200){
var jsonData = Ext.util.JSON.decode( req.responseText );
var unConfigedData = jsonData.unConfiged;
var configedData = jsonData.configed;
var unConfigedCCData, configedCCData;
for ( var i=0; i<unConfigedData.length; i++ ){
var ccData = unConfigedData[i];
if ( ccData.cc == "testcc" ){
unConfigedCCData = ccData;
break;
}
}
for ( var i=0; i<configedData.length; i++ ){
var ccData = configedData[i];
if ( ccData.ccid == "testcc" ){
configedCCData = ccData;
break;
}
}
unConfigedStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(unConfigedCCData),
reader: new Ext.data.JsonReader({
root: 'items'
},[
{name: 'name', mapping: 'name' },
{name: 'type', mapping: 'type' }
])
});
configedStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(configedCCData),
reader: new Ext.data.JsonReader({
root: 'items'
},[
{name: 'name', mapping: 'name' },
{name: 'type', mapping: 'type' }
])
});
unConfigedGrid = new Ext.grid.Grid('unConfigedDiv', {
ds: unConfigedStore,
cm: columnModel,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});
configedGrid = new Ext.grid.Grid('configedDiv', {
ds: configedStore,
cm: columnModel,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});
unConfigedGrid.render();
configedGrid.render();
} else {
alert("HTTP error: " + req.status);
}
}
};
req.open("POST", "my_config.do?c=CONDITION_CONFIG_INIT", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
this.req= req;
this.unConfigedStore= unConfigedStore;
this.configedStore= configedStore;
this.columnModel= columnModel;
this.unConfigedGrid= unConfigedGrid;
this.configedGrid= configedGrid;
}
};
}();
Ext.EventManager.onDocumentReady(MyConditionConfig.init, MyConditionConfig, true);
And unConfigedCCData is
{"cc":"testcc", "items":[{"index":1,"type":"Attribute","name":"unconfigedaaa","nType":0,"id":"testid"},{"index":2,"type":"Attribute","name":"unconfigedbbb","nType":0,"id":"testid2"},{"index":3,"type":"AttributeGroup","name":"unconfigedccc","nType":1,"id":"testid3"}]}
ConfigedCCData is
{"cc":"testcc", "items":[{"index":1,"type":"Attribute","name":"configedaaa","nType":0,"id":"testid"},{"index":2,"type":"Attribute","name":"configedbbb","nType":0,"id":"testid2"},{"index":3,"type":"AttributeGroup","name":"configedccc","nType":1,"id":"testid3"}]}
But in my page, grid only have title colmns "Name", "Type". No results. Where I made a mistake? Thanks.
/*myconfig.js*/
var MyConditionConfig = function () {
var req, unConfigedStore, configedStore, columnModel, unConfigedGrid, configedGrid ;
return {
init : function() {
columnModel = new Ext.grid.ColumnModel([{
header: "Name",
dataIndex: 'name',
width: 100
}, {
header: "Type",
dataIndex: 'type',
width: 50
}]);
req = new ActiveXObject("Msxml2.XMLHTTP");
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200){
var jsonData = Ext.util.JSON.decode( req.responseText );
var unConfigedData = jsonData.unConfiged;
var configedData = jsonData.configed;
var unConfigedCCData, configedCCData;
for ( var i=0; i<unConfigedData.length; i++ ){
var ccData = unConfigedData[i];
if ( ccData.cc == "testcc" ){
unConfigedCCData = ccData;
break;
}
}
for ( var i=0; i<configedData.length; i++ ){
var ccData = configedData[i];
if ( ccData.ccid == "testcc" ){
configedCCData = ccData;
break;
}
}
unConfigedStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(unConfigedCCData),
reader: new Ext.data.JsonReader({
root: 'items'
},[
{name: 'name', mapping: 'name' },
{name: 'type', mapping: 'type' }
])
});
configedStore = new Ext.data.Store({
proxy: new Ext.data.MemoryProxy(configedCCData),
reader: new Ext.data.JsonReader({
root: 'items'
},[
{name: 'name', mapping: 'name' },
{name: 'type', mapping: 'type' }
])
});
unConfigedGrid = new Ext.grid.Grid('unConfigedDiv', {
ds: unConfigedStore,
cm: columnModel,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});
configedGrid = new Ext.grid.Grid('configedDiv', {
ds: configedStore,
cm: columnModel,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false
});
unConfigedGrid.render();
configedGrid.render();
} else {
alert("HTTP error: " + req.status);
}
}
};
req.open("POST", "my_config.do?c=CONDITION_CONFIG_INIT", true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send(null);
this.req= req;
this.unConfigedStore= unConfigedStore;
this.configedStore= configedStore;
this.columnModel= columnModel;
this.unConfigedGrid= unConfigedGrid;
this.configedGrid= configedGrid;
}
};
}();
Ext.EventManager.onDocumentReady(MyConditionConfig.init, MyConditionConfig, true);
And unConfigedCCData is
{"cc":"testcc", "items":[{"index":1,"type":"Attribute","name":"unconfigedaaa","nType":0,"id":"testid"},{"index":2,"type":"Attribute","name":"unconfigedbbb","nType":0,"id":"testid2"},{"index":3,"type":"AttributeGroup","name":"unconfigedccc","nType":1,"id":"testid3"}]}
ConfigedCCData is
{"cc":"testcc", "items":[{"index":1,"type":"Attribute","name":"configedaaa","nType":0,"id":"testid"},{"index":2,"type":"Attribute","name":"configedbbb","nType":0,"id":"testid2"},{"index":3,"type":"AttributeGroup","name":"configedccc","nType":1,"id":"testid3"}]}
But in my page, grid only have title colmns "Name", "Type". No results. Where I made a mistake? Thanks.