PDA

View Full Version : Pass Variable store to Url Store



myput
4 Oct 2011, 4:58 AM
Hello,

I Have a store with extraParams who contain an ID. I would like to pass the ID at the end of the url store.
I have:


WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
model: "WPApp.models.DirectoryCategoryListModel",
proxy: {
type: 'ajax',
url: "http://localhost:8888/WPapp/app/php/getCategoryList.php",
reader: {
type: 'json'
}
},
setId: function (id) {
this.itemId = id;
},
extraParams: {
id: this.itemId,
},
autoLoad: true
});


I would like to have if this.itemId = 2

url: "http://localhost:8888/WPapp/app/php/getCategoryList.php?id=2"
when i put the url like that with raw values, it's working.
i tried to concat the variable to URL, and create a new extra param with the url, but don't work.

In my PHP file, the URL, i have:


$id = $_GET['id'];
$request = "SELECT * FROM CategoryList WHERE IDBASELIST = $id";
echo (getJsonString($request, $dbName));



I don't really understand how i can give this extra Params to my URL
Someone can help me please?

katamshut
4 Oct 2011, 5:37 AM
you should check what url your browser sends to the server. it is easy to check with chrome (debug mode).

and for your problem try to do like this:



WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
model: "WPApp.models.DirectoryCategoryListModel",
proxy: {
type: 'ajax',
url: "http://localhost:8888/WPapp/app/php/getCategoryList.php",
reader: {
type: 'json'
},
extraParams: {
id: this.itemId,
}
},
setId: function (id) {
this.itemId = id;
},
autoLoad: true
});



extraParams cannot be a part of Ext.data.Store. It is a part of the Ext.data.Proxy class.

myput
4 Oct 2011, 5:50 AM
Okey,
First thanks for your answer,


I corrected the code and put Params in the proxy but no work.
i try to read the JS debuger in chrome,

it say:


Refused to set unsafe header "User-Agent"sencha-touch.js:6Uncaught Ext.data.JsonReader.getResponseData: Unable to parse JSON returned by Server.Ext.data.JsonReader.Ext.extend.getResponseDatasencha-touch.js:6Ext.data.Reader.Ext.extend.readsencha-touch.js:6(anonymous function)sencha-touch.js:6Ext.data.Connection.Ext.extend.onCompletesencha-touch.js:6Ext.data.Connection.Ext.extend.onStateChangesencha-touch.js:6(anonymous function)
Juste that i think hehe. Sorry it's the first time i use that.

have you an Idea?

myput
4 Oct 2011, 7:27 AM
Ok i have the solution, i don't know if it's the best but it's working:

Store:


WPApp.stores.DirectoryCategoryListStore = new Ext.data.Store({
model: "WPApp.models.DirectoryCategoryListModel",
storeId: 'DirectoryCategoryListStore',
proxy: {
type: 'ajax',
url: "http://localhost:8888/WPapp/app/php/getCategoryList.php",
reader: {
type: 'json'
},
},
setId: function (id) {
this.itemId = id;
WPApp.stores.DirectoryCategoryListStore.load({params:{id:this.itemId}});
},
autoLoad: true
});


Thanks for your help :)

katamshut
5 Oct 2011, 1:23 AM
no prob.

If this is working for you then it is ok. I tried to reproduce your problem without luck. but anyways use the chrome debugger. It is very powerful and gives you any information you need. If you really want to know whats wrong then you have to debug sencha code. Therefore use the sencha-touch-debug-w-comments.js to debug.

cheers
Chris

jakeed2
12 Feb 2013, 10:59 AM
I needed to do this to use the ListPaging Plugin

Add a listener to your store.. The API I call requires a token for each request. I was able to set my store with the token "beforeload" .. then when the ListPaging function is called, my token is already part of the proxy.


Ext.define('MyApp.store.StudentStore',{
extend: 'Ext.data.Store',
config:{
storeId: 'Students',
model:'MyApp.model.PeopleModel',
autoLoad:false,
clearOnPageLoad: false,

listeners: {
beforeload: function(store){

store.setProxy({
headers: {
Accept : 'application/json',
Authorization : 'Bearer:' + this.token
},
type: 'ajax',
pageParam: 'pageindex',
url:'https://localhost/MyApp/GetUsers.json',
extraParams: {
schoolId : 1,
roleName: 'student'
},
reader: {
type: 'json',
rootProperty:'data'
}
});
},
load: function(store){
console.log(store);
}
},

grouper: {
groupFn: function(record) {
return record.get('lastname')[0];

}
},
sorters: 'lastname'
},
setToken: function(token){
this.token = token;
}

});