1. #1
    Touch Premium Member
    Join Date
    Aug 2010
    Location
    New York, NY
    Posts
    66
    Answers
    2
    Vote Rating
    0
    sandeep45 is on a distinguished road

      0  

    Question 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:

    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
    		}
    	}
    });
    Here is my Reader:

    Code:
    Ext.define("Desk.reader.DeskReader",{
    	extend: 'Ext.data.reader.Json',
    	xtype: 'deskReader',
    
    
    	config: {
    		rootProperty: 'resources',
    		type: 'json'
    		idProperty: 'uri'
    	}
    });
    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.

    On the other hand if i was to define my model like this, it works perfectly fine:


    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: {
    			    type: 'json',
    			    rootProperty: 'resources',
    			    idProperty: 'uri'
    			},
    			appendId: false,
    			pageParam:false,
    			limitParam:false,
    			startParam:false
    		}
    	}
    });
    What am i doing wrong when define my own reader. Any help is appreciated

  2. Your reader shouldn't use xtype, xtype is only for components. You need to give your reader an alias:

    Code:
    alias : 'reader.myjson'
    And now you can use

    Code:
    type : 'myjson'
    in your reader config.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,994
    Answers
    3487
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    Your reader shouldn't use xtype, xtype is only for components. You need to give your reader an alias:

    Code:
    alias : 'reader.myjson'
    And now you can use

    Code:
    type : 'myjson'
    in your reader config.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Touch Premium Member
    Join Date
    Aug 2010
    Location
    New York, NY
    Posts
    66
    Answers
    2
    Vote Rating
    0
    sandeep45 is on a distinguished road

      0  

    Default


    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.



    Quote Originally Posted by mitchellsimoens View Post
    Your reader shouldn't use xtype, xtype is only for components. You need to give your reader an alias:

    Code:
    alias : 'reader.myjson'
    And now you can use

    Code:
    type : 'myjson'
    in your reader config.

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,994
    Answers
    3487
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  6. #5
    Touch Premium Member
    Join Date
    Aug 2010
    Location
    New York, NY
    Posts
    66
    Answers
    2
    Vote Rating
    0
    sandeep45 is on a distinguished road

      0  

    Default


    Then how come xtype setup works for 'Ext.data.proxy.Ajax' ?

    Quote Originally Posted by mitchellsimoens View Post
    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.