-
6 Jun 2012 5:27 AM #1
Answered: How to define my own json reader and use it in all other proxies?
Answered: How to define my own json reader and use it in all other proxies?
I am trying to extend 'Ext.data.reader.Json' and have my own json reader. Now in my proxies and models when i need a reader i just use the xtype of my extended reader. This is not working. Its not using my reader and therefore i am unable to read the data. Now if i was to create the reader inline it works fine. There is something wrong in the way I am extending it coz thats the only time when it doesn't work.
Here is my model:
Here is my Reader:Code:Ext.define('Desk.model.User',{ extend: 'Ext.data.Model', requires: [ 'Desk.proxy.DeskProxy', 'Desk.reader.DeskReader' ], config: { idProperty: 'uri', fields: [ { name: 'email', type: 'string' }, { name: 'public_name', type: 'string' }, { name: 'uri', type: 'string' }, { name: 'level', type: 'string' } ], proxy: { xtype: 'deskProxy', url: '', reader: { xtype: 'deskReader' }, appendId: false, pageParam:false, limitParam:false, startParam:false } } });
When i do a load on my store/model it makes the call but is unable to read all the data as it never used my reader and thus doesn't know the rootProperty value.Code:Ext.define("Desk.reader.DeskReader",{ extend: 'Ext.data.reader.Json', xtype: 'deskReader', config: { rootProperty: 'resources', type: 'json' idProperty: 'uri' } });
On the other hand if i was to define my model like this, it works perfectly fine:
What am i doing wrong when define my own reader. Any help is appreciatedCode:Ext.define('Desk.model.User',{ extend: 'Ext.data.Model', requires: [ 'Desk.proxy.DeskProxy', 'Desk.reader.DeskReader' ], config: { idProperty: 'uri', fields: [ { name: 'email', type: 'string' }, { name: 'public_name', type: 'string' }, { name: 'uri', type: 'string' }, { name: 'level', type: 'string' } ], proxy: { xtype: 'deskProxy', url: '', reader: { type: 'json', rootProperty: 'resources', idProperty: 'uri' }, appendId: false, pageParam:false, limitParam:false, startParam:false } } });
-
Best Answer Posted by mitchellsimoens
Your reader shouldn't use xtype, xtype is only for components. You need to give your reader an alias:
And now you can useCode:alias : 'reader.myjson'
in your reader config.Code:type : 'myjson'
-
8 Jun 2012 5:15 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Your reader shouldn't use xtype, xtype is only for components. You need to give your reader an alias:
And now you can useCode:alias : 'reader.myjson'
in your reader config.Code:type : 'myjson'
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Jun 2012 1:24 PM #3
Thanks for the input. Can you share with me how I could figure this out myself. The first thing I thought was to look at the hierarchy chain and see if the class extends from Component. Then i saw proxy class working with xtype and it also doesnt extend from Component.
To summarize, How can i tell which classes can be extended and used as personal xtypes?
PS: If the answer is by looking something up in the source, please don;t hesitate in sharing that.

-
11 Jun 2012 1:35 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
xtype is only for components. A component is defined by being a subclass of Ext.Component at any level. So Ext.Container extends Ext.Component so it can use xtype. Ext.Panel extends Ext.Container who extends Ext.Component so Ext.Panel can use xtype.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
11 Jun 2012 1:54 PM #5


Reply With Quote