Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Does Extjs4.2 support Ext.data.ArrayReader?

  1. #1
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default Answered: Does Extjs4.2 support Ext.data.ArrayReader?

    Dear ?
    I use Extjs 4.2.1
    I want to try " Ext.data.ArrayReader" as below.
    I it show Error at " var myRecord = Ext.data.Record.create ".
    the message:
    Uncaught TypeError: Cannot read property 'items' of undefined

    Does Extjs4.2 support Ext.data.ArrayReader?

    Code:
    Ext.onReady(function(){
      var cities = [["1", "A01"], ["2", "A02"], ["3", "A03"], ["4", "A04"]];
      var mp = new Ext.data.MemoryProxy(cities);  
      
      var myRecord = Ext.data.Record.create(
                    [{ name:'cid',        type:'int',    mapping:0 },
                     { name:'cname', type:'string', mapping:1 }
                   ]
                );
       var myReader = new Ext.data.ArrayReader({}, myRecord);        
       
       var store = new Ext.data.Store({
        proxy: mp,
        reader: myReader
       });
           
       console.log(store.getCount());          
    });

  2. The example in the docs is awful.

    Try this:


  3. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    There's an example on the doc page that should help.
    http://docs.sencha.com/extjs/4.2.1/#...a.reader.Array

  4. #3
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default

    Dear : Thx for your help! but as the code bellow?
    it show count=0. Is there some thing wrong?
    THX.

    Code:
        
        Employee = Ext.define('Employee', {
           extend: 'Ext.data.Model',
           fields: [
            'id',
            {name: 'name', mapping: 1},         // "mapping" only needed if an "id" field is present which
            {name: 'occupation', mapping: 2}    // precludes using the ordinal position as the index.        
          ]
        });
        
        var emp = [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ];
        
        //var mp = new Ext.data.MemoryProxy(emp);
        
        var myReader = new Ext.data.reader.Array({
              model: 'Employee'
             }, emp);
    
    
    
       var store = new Ext.data.Store({
           proxy: { type: 'memory'}
          ,reader: myReader
       });
           
       console.log(store.count());

  5. #4
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    The example in the docs is awful.

    Try this:


  6. #5
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default

    Dear?
    Thx, You use Ext.data.Store Directory.
    It doesn;t use

    new Ext.data.reader.Array to build proxy naymore?

    THX!

  7. #6
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    This bit creates an Ext.data.reader.Array:

    Code:
    reader: {
        type: 'array'
    }
    You shouldn't need to create one directly but it would be something like this:

    Code:
    new Ext.data.reader.Array({
        model: 'Employee'
    });
    In the docs it passes the model twice, which is wrong.

  8. #7
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default

    Dear skirtle?
    Thank for your help.

    1.so, Now does't use ?
    Code:
     new Ext.data.reader.Array({     model: 'Employee' });
    just use the sample your writed.

    i had try to use new Ext.data.reader.Array({ model: 'Employee' }) + new Ext.data.Store()
    But , Don't work.

    2.Does other "Reader" are the same with your sample ?

    THX

  9. #8
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    See the docs for Json reader, they're much better. Configuring an Array reader works just the same way. The reader class is set via the type config, which matches the class alias.

    Configuring proxies and readers is always done via configs rather than by directly instantiating them yourself.

    Your original example seemed to be based on ExtJS 3 or earlier. Almost every line is wrong in some way from an ExtJS 4 perspective. Follow the examples given in the docs for Json reader and you can't go far wrong.

  10. #9
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default

    Dear skirtle? Thank you very much .

  11. #10
    Sencha User
    Join Date
    Apr 2014
    Posts
    44
    Answers
    1

    Default

    Sorry?
    can I ask you another question?
    as th code bellow?
    I use store.load ,and I want to statr from 2 ?get 1 row.
    But,It doesn't work?
    store.getAt(0).get('name') show =>Bill
    store.count() ==>5

    Code:
        Ext.define('Employee',{
              extend: 'Ext.data.Model',
              fields: [
                {name:'id',         type:'int'   ,mapping:0 },
                {name:'name',       type:'string',mapping:1 },
                {name:'occupation', type:'string',mapping:2 }         
              ]
          });
          
        
        
        var dataSource=[[1, 'Bill', 'Gardener']
                       ,[2, 'Ben', 'Horticulturalist']
                       ,[3, 'Ben3', 'Horticulturalist3']
                       ,[4, 'Ben4', 'Horticulturalist4']
                       ,[5, 'Ben5', 'Horticulturalist5']
                       ]; 
        var store = new Ext.data.Store({
           model: 'Employee',    
           data: dataSource,    
           proxy: {
            type: 'memory',        
            reader: {
                type: 'array'
              }
           }
       });
    
    
       store.load({
               start:3,
               limit:1
       });
    
         
        console.log(store.getAt(0).get('name'));
        console.log(store.count());

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •