1. #1
    Ext User
    Join Date
    Jan 2008
    Posts
    14
    Vote Rating
    0
    dombroskib is on a distinguished road

      0  

    Default Stores and Models

    Stores and Models


    Trying to play with the kiva sample and convert it to use a regular store with a JsonReader backing it (reusing the back end from extjs development). I can't get it to work as I get an error that the model is undefined in ext-touch-debug line 11505.
    Code:
    Ext.regModel('CheckModel', {
    fields: [
    {name:'APAmount'},
    {name:'Provider'},
    {name:'ARAmount'},
    {name:'ProfitAmt'},
    {name:'ProfitPercent'},
    {name:'State'},
    {name:'City'},
    {name:'Claimant'},
    {name:'Payer'},
    {name:'ApptDate'},
    {name:'ApptType'},
    {name:'Department'},
    {name:'Speciality'}
    ]
    });
     
     
    this.store = new Ext.data.Store({
    id: 'edc-store-checks',
    storeId: 'edc-check-store',
    url: '/MessageHub.aspx',
    model: 'CheckModel',
    reader: new Ext.data.JsonReader({
    root: 'Items',
    totalProperty: 'Count',
    id: 'openitems',
    model: 'CheckModel'
    
    })
    });

    Tried stepping thru the code (learning experience on doing that in Safari) and don't ever see a key being added to the underlying mixedcollection of the ModelMgr. Am I missing something (.90 version of touch).

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Location
    Buenos Aires, Argentina
    Posts
    67
    Vote Rating
    1
    elmasse is on a distinguished road

      0  

    Default


    Got the same issue, I just modified the code, try this:

    Not a nice solution, but it is working for me. The main issue is automatically registering writers and readers since they are created automatically and no root, model and so on are attached

    Code:
    Ext.data.JsonReader.override({
        buildExtractors : function() {
    		if (typeof this.model == 'string') {
    			this.model = Ext.ModelMgr.types[this.model];
    		}
    	    Ext.data.JsonReader.superclass.buildExtractors.apply(this, arguments);
    	
    	    if (this.root) {
    	        this.getRoot = this.createAccessor(this.root);
    	    } else {
    	        this.getRoot = function(root) {
    	            return root;
    	        };
    	    }
    	}
    });
    
    Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
        /**
         * @cfg {Ext.data.DataReader} reader @hide
         */
        constructor: function(config){
    		if(config && config.url){
    			config.proxy = new Ext.data.AjaxProxy(config);
    		}
            Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
                reader: new Ext.data.JsonReader(config)
            }));
        }
    });
    Ext.reg('jsonstore', Ext.data.JsonStore);

  3. #3
    Ext User
    Join Date
    Jan 2008
    Posts
    14
    Vote Rating
    0
    dombroskib is on a distinguished road

      0  

    Default


    That seemed to do the trick, thank you! Don't seem to get the load listener to work either. Did you have issues with it?

  4. #4
    Ext User
    Join Date
    Jan 2008
    Posts
    14
    Vote Rating
    0
    dombroskib is on a distinguished road

      0  

    Default


    Now read the docs, event is no longer there.

  5. #5
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    In Sencha Touch the data package was rearchitected such that Stores have Proxies, which in turn contain their Readers and Writers, like this:

    Code:
     
    this.store = new Ext.data.Store({
        id: 'edc-store-checks',
        storeId: 'edc-check-store',
        url: '/MessageHub.aspx',
        model: 'CheckModel',
        proxy: {
            type: 'ajax',
            reader: {
                type: 'json',
                root: 'Items',
                totalProperty: 'Count'
            }
        }
    });
    Defining a Reader directly on a Store is not currently supported. Thanks for pointing this out though as our docs on this are currently out of date.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  6. #6
    Ext User
    Join Date
    Jan 2008
    Posts
    14
    Vote Rating
    0
    dombroskib is on a distinguished road

      0  

    Default


    Thanks Ed. Spending more time in the touch code I realise that all though I am tempted to apply all of Ext JS techniques I need to be wary that touch currently supports it. Appreciate the efforts, so far I am happy with where this is headed

  7. #7
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,360
    Vote Rating
    81
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      0  

    Default


    Quote Originally Posted by edspencer View Post
    In Sencha Touch the data package was rearchitected such that Stores have Proxies, which in turn contain their Readers and Writers, like this:

    Code:
     
    this.store = new Ext.data.Store({
        id: 'edc-store-checks',
        storeId: 'edc-check-store',
        url: '/MessageHub.aspx',
        model: 'CheckModel',
        proxy: {
            type: 'ajax',
            reader: {
                type: 'json',
                root: 'Items',
                totalProperty: 'Count'
            }
        }
    });
    Defining a Reader directly on a Store is not currently supported. Thanks for pointing this out though as our docs on this are currently out of date.
    That is f'ing sexy! Total abstraction, and really makes configuration extremely easy.

    I really hope this makes it in to 4.0

  8. #8
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Quote Originally Posted by jgarcia@tdg-i.com View Post
    That is f'ing sexy! Total abstraction, and really makes configuration extremely easy.

    I really hope this makes it in to 4.0
    Sencha Touch's data package is the 4.0 data package - they are identical. There's a lot more to come too
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  9. #9
    Ext User
    Join Date
    Nov 2009
    Posts
    24
    Vote Rating
    0
    epalm is on a distinguished road

      0  

    Default


    Quote Originally Posted by edspencer View Post
    In Sencha Touch the data package was rearchitected such that Stores have Proxies, which in turn contain their Readers and Writers, like this:

    Code:
     
    this.store = new Ext.data.Store({
        id: 'edc-store-checks',
        storeId: 'edc-check-store',
        url: '/MessageHub.aspx',
        model: 'CheckModel',
        proxy: {
            type: 'ajax',
            reader: {
                type: 'json',
                root: 'Items',
                totalProperty: 'Count'
            }
        }
    });
    This gives me "url is undefined"

  10. #10
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Put the url on the Proxy instead of the Store. The Proxy abstracts away the CRUD mechanism that the Store relies on, so a Store can switch between a LocalStorageProxy and an AjaxProxy and rely on the same interface. The url is therefore meaningful to the Proxy, not the Store.

    This was a design change from the current Ext JS 3.x architecture, we're preparing documentation to guide developers through the usage of the data package.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Similar Threads

  1. How do I write models?
    By mwmcmullen in forum Ext GWT: Discussion
    Replies: 0
    Last Post: 26 Apr 2010, 5:30 AM
  2. Stores, sub-stores & filters - help
    By Bobbin in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 15 Nov 2009, 1:10 PM
  3. XTemplate an nested models
    By screw in forum Ext GWT: Help & Discussion (1.x)
    Replies: 4
    Last Post: 13 Aug 2009, 3:53 AM
  4. XTemplate an nested models
    By screw in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 1 Feb 2009, 10:18 AM
  5. How to use Models, Binders, and Readers
    By fernando in forum Ext GWT: Help & Discussion (1.x)
    Replies: 1
    Last Post: 12 Jun 2008, 11:44 AM

Thread Participants: 5