PDA

View Full Version : Question about MemoryProxy and Jsondata



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.

justmonkey
24 Apr 2007, 3:58 AM
Oh my God, i forgot to call store.load(), sorry!! sigh...

Animal
24 Apr 2007, 4:01 AM
So it works now???

Why aren't you using HttpProxy?

Why are you using activex?

justmonkey
24 Apr 2007, 4:09 AM
So it works now???

Why aren't you using HttpProxy?

Why are you using activex?

Because i want to render two grids after one request to server. If i use HttpProxy, i may send two requests. I'm appreciate if you have better idea:)

Animal
24 Apr 2007, 4:56 AM
OK, two different sets of data for two grids?

You should really use an Ext.data.Connection to get the data for efficiency and cross-browser utility.

Docs are not there yet, but soon will be. Meanwhile you can look at the source code to figure how to use it. And look at how HttpProxy uses it.

justmonkey
24 Apr 2007, 5:12 PM
OK, I will take a look at source code about Ext.data.Connection, thank you