Reputation: 7394
I'm creating a data store that will load the data from server. I'm wondering how I can pass parameters to the proxy.
var dataStore = new Ext.data.JsonStore({
proxy:'productSearch.php',
root:'products',
fields:['title', 'image', 'inStock', 'price', 'category', 'manufacturer']
});
Upvotes: 1
Views: 4464
Reputation: 62359
I usually do it like this
var dataStore = new Ext.data.JsonStore({
url: 'productSearch.php'
root: 'products',
baseParams: { //here you can define params you want to be sent on each request from this store
param1: 'value1',
param2: 'value2'
},
fields: [...]
});
dataStore.load({
params: { //here you can define params on 'per request' basis
param3: 'value3'
}
});
I also prefer to define fields like this:
fields: [
{name: 'title', mapping: 'title', type: 'string'},
{name: 'image', mapping: 'image', type: 'string'},
{name: 'inStock', mapping: 'inStock', type: 'bool'},
{name: 'price', mapping: 'price', type: 'float'},
{name: 'category', mapping: 'category', type: 'int'},
{name: 'someDate', mapping: 'someDate', type: 'date', dateFormat: 'Y-m-d'},
]
Two things here:
I assign the types, so that the store is loaded with correct datatypes. It will even convert string dates to JavaScript Date() objects.
I use 'mapping' parameter, to tell which fields from JSON are to be matched to which fields in the store. If for whatever reason JSON format changes, I only need to make one change here.
Upvotes: 7