-
4 Oct 2011 4:58 AM #1
Pass Variable store to Url Store
Pass Variable store to Url Store
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:
I would like to have if this.itemId = 2Code: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 });
when i put the url like that with raw values, it's working.HTML Code:url: "http://localhost:8888/WPapp/app/php/getCategoryList.php?id=2"
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:
I don't really understand how i can give this extra Params to my URLCode:$id = $_GET['id']; $request = "SELECT * FROM CategoryList WHERE IDBASELIST = $id"; echo (getJsonString($request, $dbName));
Someone can help me please?
-
4 Oct 2011 5:37 AM #2
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:
extraParams cannot be a part of Ext.data.Store. It is a part of the Ext.data.Proxy class.Code: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 });
-
4 Oct 2011 5:50 AM #3
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:
Juste that i think hehe. Sorry it's the first time i use that.HTML Code: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)
have you an Idea?
-
4 Oct 2011 7:27 AM #4
Ok i have the solution, i don't know if it's the best but it's working:
Store:
Thanks for your helpCode: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 });
-
5 Oct 2011 1:23 AM #5
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
-
12 Feb 2013 10:59 AM #6
Success
Success
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.
Code: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; } });


Reply With Quote