PDA

View Full Version : How can I get data?



Valera
31 Jul 2012, 1:10 PM
{
"a":7,
"b":26,
"c":40,
"records":[
{"aa":"1","bb":"2"}
]
}

How can I get data a,b,c from Ext.data.Store ?

scottmartin
31 Jul 2012, 1:31 PM
Is the data already in the store? Where do you want it? in a form?

Scott.

Valera
31 Jul 2012, 2:04 PM
in constructing the grid, I get the data, but can not apply to them

scottmartin
31 Jul 2012, 2:31 PM
Here is a basic example:



{
'items': [
{
'name': 'Lisa',
'email': 'lisa@simpsons.com',
'change': 100
},
{
'name': 'Bart',
'email': 'bart@simpsons.com',
'change': -20
},
{
'name': 'Homer',
'email': 'home@simpsons.com',
'change': 23
},
{
'name': 'Marge',
'email': 'marge@simpsons.com',
'change': -11
}
]
}




Ext.onReady(function(){

Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'change',],
autoLoad: true,
proxy: {
type: 'ajax',
url: 'data.json',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ header: 'Name', dataIndex: 'name' },
{ header: 'Email', dataIndex: 'email', flex: 1 },
{ header: 'Change', dataIndex: 'change' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});

});

Valera
31 Jul 2012, 2:42 PM
need these data to obtain: (total,closed,itc BEFORE items)

{
'total':200,
'closed':300,
'itc':'zzz...'
'items': [
{
'name': 'Lisa',
'email': 'lisa@simpsons.com',
'change': 100
},
{
'name': 'Bart',
'email': 'bart@simpsons.com',
'change': -20
},
{
'name': 'Homer',
'email': 'home@simpsons.com',
'change': 23
},
{
'name': 'Marge',
'email': 'marge@simpsons.com',
'change': -11
}
]
}

these data are easily transferred from the server after the recount than on the client

sampl:
37644

in order not to perform this function:


var size = 0; var foldersCount = 0; var filesCount = 0;
this.store.each(function(record) {
if(record.get('filesize') !== '-'){
size = Number(size + record.get('filesize'));
filesCount++;
}
else {foldersCount++;}
});

scottmartin
31 Jul 2012, 8:02 PM
Are you referring to the totalProperty, etc?

Scott.

Valera
1 Aug 2012, 12:13 AM
yes yes yes :)

and any other data, not only totalProperty.

scottmartin
1 Aug 2012, 7:00 AM
The server JSON should return these values in the result set and you simply need to set these values in your reader and it will be used.



reader : {
type : 'json',
totalProperty : 'total',
successProperty : 'success',
messageProperty : 'message',
root : 'items'
},


Scott.

Valera
1 Aug 2012, 2:25 PM
Thank you!