Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    13
    Vote Rating
    0
    cdonnellytx is on a distinguished road

      0  

    Default ArrayStore/ArrayReader broken in 0.94

    ArrayStore/ArrayReader broken in 0.94


    Hi all,

    It appears that neither the ArrayStore nor the ArrayReader are working properly after updating to 0.94. In fact, the example in the ArrayStore docs does not work:
    Code:
    var store = new Ext.data.ArrayStore({
        // store configs
        autoDestroy: true,
        storeId: 'myStore',
        // reader configs
        idIndex: 0,
        fields: [
           'company',
           {name: 'price', type: 'float'},
           {name: 'change', type: 'float'},
           {name: 'pctChange', type: 'float'},
           {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
        ]
    });
    
    var myData = [
        ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
        ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
        ['Boeing Co.',75.43,0.53,0.71,'9/1 12:00am'],
        ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
        ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
    ];
    
    store.loadData(myData);
    
    var rec = store.getAt(0);
    console.debug('company: ', rec.get('company')); // this should work, but doesn't
    console.debug('0:', rec.get('0'));              // this does, but shouldn't
    console.debug(rec.data);
    prints the following:

    Code:
    company: 
    0: 3m Co
    {
    	"0": "3m Co",
    	"1": 71.72,
    	"2": 0.02,
    	"3": 0.03,
    	"4": "9/1 12:00am",
    	"company": "",
    	"price": 0,
    	"change": 0,
    	"pctChange": 0,
    	"lastChange": null
    }
    Shouldn't the rec.data look like

    Code:
    {
    	"company": "3m Co",
    	"price": 71.72,
    	"change": 0.02,
    	"pctChange": 0.03,
    	"lastChange": "9/1 12:00am"
    }
    instead?
    Last edited by cdonnellytx; 12 Sep 2010 at 2:54 PM. Reason: Forgot the loadData() call.

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,170
    Vote Rating
    674
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    When calling loadData, the format is always the same regardless of the reader:

    Code:
    loadData([{
        field1: 'a',
        field2: 'b'
    },{
        field1: 'c',
        field2: 'd'
    }]);
    I'll add some extra notes to loadData to reflect this.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    13
    Vote Rating
    0
    cdonnellytx is on a distinguished road

      0  

    Default


    Quote Originally Posted by evant View Post
    I'll add some extra notes to loadData to reflect this.
    This also appears to be the case for the data property as well.

    So I have a couple of questions:

    * At this point, what is the difference between Ext.data.Store and Ext.data.ArrayStore (and JsonStore, etc.)? Is the latter deprecated? Or is it simply a Store that defaults to loading an ArrayReader?
    * This differs from how ExtJS interprets the same code; in ExtJS (as of 3.2.2), it maps the data into the record's preferred structure. Is this going to change in a future version of ExtJS as well?

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,170
    Vote Rating
    674
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    1) It's not really overly useful.
    2) Touch and Ext 4 will share the same data package, so yes, this behaviour is likely to change.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  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


    There are really two main ways of loading data into a Store - via its configured Proxy or doing it manually. When going via any kind of Proxy that interacts with a server (any ServerProxy subclass), the configured Reader is used to decode the server's response, using any mappings on the model fields in case the server's field names are for some reason.

    When loading data manually we assume you already have it in the correct format. This may be an incorrect assumption and I welcome feedback but it strikes me as reasonable that your local data is already a known format.

    We're currently working on getting Store up to 1.x quality so a few of these things are still in flux.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  6. #6
    Ext JS Premium Member
    Join Date
    May 2007
    Posts
    13
    Vote Rating
    0
    cdonnellytx is on a distinguished road

      0  

    Default


    My main issue is that we (at my company) are developing a mobile version of our existing webapp, and so we are leveraging both existing server-side and client-side code (the latter in the form of a base class, which is subclassed in both the desktop webapp (which uses ExtJS 3.x) and the mobile webapp (using Sencha Touch). Many of the smaller data lists (mainly used to drive combo/select lists) are sent down as auxiliary properties in a larger JSON object as arrays (to reduce the number of round trips as well as bandwidth used), and are hydrated into records via ArrayStores in the main webapp.

    I have devised a workaround for now where
    1. Store creation is now done in the webapp-specific subclasses, not the base class.
    2. In the Sencha Touch webapp, I am doing something like
    Code:
        createMyStore: function (data) {
            var model = 'MyModel';
    
            // Ensure the model is loaded.
            if (!Ext.ModelMgr.getModel(model)) {
                Ext.regModel(model, {
                    fields: ['id','foo','bar','baz']
                });
            }
    
            // Create the store and read the data.        
            var store = new Ext.data.Store({
                autoDestroy: true,
                model: model,
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'array',
                        model: model
                    }
                }
            });
            
            if (data) {
                store.loadRecords(store.proxy.reader.read(data).records);
            }
            return store;
    I specify the model twice in cases where the Store can either read records from a locally constructed block as well as do read()s against a JSON web service. While that does work, it is somewhat of a large block of code to replicate. If there were a way to make it cleaner/less cumbersome (particularly the loadRecords statement) that would work.

    Thanks,
    # Chris

  7. #7
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Posts
    862
    Vote Rating
    21
    jep will become famous soon enough jep will become famous soon enough

      0  

    Default


    Argh, yet another Sencha Touch pitfall that I stepped into, burning an hour of my time figuring out why mode code isn't working, breaking it out into an isolated project, trying it there, then trying to Sencha code in docs, scratching my head, etc.

    I agree with Chris that it's vital to be able to load data into a store both locally and from a remote source. Not everything fits the exact same set of rails you have nailed onto Store. You're hobbling its functionality by not allowing it to load data locally. In my case, I have an existing code base that uses data that another piece of code is loading from the server. It spits it back as an array. I then wanted to load it into Store. But it appears now that the only way for me to do that and have it work is to rewrite ALL my code in one gulp. That's an incredibly hard thing to do. Or I have to write a bunch of shim code, which is needlessly time consuming and hard to maintain.

    If nothing else, there needs to be HUGE glaring warnings around loadData in the docs to educate on how it completely short-circuits the useful behavior you think you are getting.

  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


    Are you referring to the same point above (the idea that loadData should use the Proxy's Reader to decode the data)?
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  9. #9
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Posts
    862
    Vote Rating
    21
    jep will become famous soon enough jep will become famous soon enough

      0  

    Default


    Yup. Either via loadData or through another function (with loadData marked in the docs with some big warning signs). I have yet to actually get to a point where I can use a Proxy with any of our existing code base. There's always a little something that is incompatible.

  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


    Ok, I see the benefits of doing this (although it does somewhat abuse Demeter). I've added a feature to develop this
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Similar Threads

  1. Arraystore in ComboBox
    By Christian-mo in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 5 Aug 2010, 5:10 AM
  2. ArrayStore example
    By meyerovb in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 21 Jul 2010, 7:39 AM
  3. DataView with ArrayStore
    By isit.gd in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 27 May 2010, 12:36 PM
  4. help with arraystore
    By ballibum in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 17 Dec 2009, 3:12 AM
  5. ArrayStore with JSON
    By Nawabu in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 21 Oct 2009, 3:44 AM

Thread Participants: 3

Tags for this Thread