PDA

View Full Version : [Noob Question] Send complex Object to JSON Store



Kurt001
13 Mar 2011, 3:43 AM
Hi there,

I receive a Json object from the server and now I need to create a store for this.
But the object is quite complex and I need a starting point how to think, to solve this.
How would the model and store would look like so that I can add Ajax.Object in there?
Can you give me an example to the following structure:



Object
IsSearch: true
MyGames: Array (25)
0: Object
storedInFolder: 3
Game: Object
jumps: false
runsOn: Object
Win: "007"
Max: false
details: Object
howGood: "10/10"
publishingDate: "12.12.1982"
stillAvailable:false
1: Object
storedInFolder: 3
... (and so on)


I have mainly problems with the objects inside the object and how to show this inside the model for the store. Here is a try, which did not work:



Ext.regModel('ajaxObject.model', {
fields: [
'storedInFolder',
'Game',
'jumps',
'runsOn',
'Win',
'Max',
'details',
'howGood',
'publishingDate',
'stillAvailable'
]
});


Please let me know how to set up the model.

Bucs
13 Mar 2011, 7:29 AM
Not sure a model is the way to go when your JSON object is that nested. You might be better manually pulling down the object and loading into the store, something like this:



Ext.Ajax.request({
url: 'url/getData',
params: {
param1: 'someValue'
},
success: function (response, opts) {
// Decode the response into a JSON object
jsonResponse = Ext.decode(response.responseText);

var store = Ext.getCmp('yourStoreId');
// OR if store is configured with 'storeId' property, you can use
// store = Ext.StoreMgr.lookup('storeId');

// Ensure you have results
if (jsonResponse.results) {
if (jsonResponse.results.length > 0) {
store.loadData(jsonResponse.results, false);
.....



Give that a shot, hopefully it gets you pointed in the right direction.

Sree vidhya
14 Jul 2011, 1:28 AM
Hi,
I have an issue with Json query.
I am using Javascript, json and dojo for display. I have a grid where i display a set of records. I have filter option where i can customize by giving my own filter. If i give constructing json query like != as <> and *a* , it is working fine.
My requirement is filter should also work for !=*a* which means it should return string which doesnt have letter 'a'.

Please help me in achieving the same..Thanks.

AndreaCammarata
14 Jul 2011, 8:06 AM
Hi Kurt001.
You can do it without problem with model definition and associations.
Post me the json you want lo load (just give me one or two elements for big array) and I will write you an example on how to do it.