开发者

How to load data into store using a MemoryProxy

I'm trying to load a JSON store using a MemoryProxy (I need to us开发者_Python百科e a proxy because I use different sources depending on the scenario). It kinda looks like this:

var data = Ext.decode(gridArrayData);
var proxy = new Ext.data.MemoryProxy(data);

var store = new Ext.data.GroupingStore({               
    proxy: proxy
});
store.load();

However when I inspect this I can see that the proxy has 10 rows of data, but not the store. I'm lost as to why.

Any pointers?


so I was missing the Arrayreader I modified the arrray example that comes with extjs replacing the arrayStore with the following

 var nameRecord = Ext.data.Record.create([                            
      {name: 'company'},
       {name: 'price', type: 'float'},
       {name: 'change', type: 'float'},
       {name: 'pctChange', type: 'float'},
       {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]);

var arrayReader = new Ext.data.ArrayReader({}, nameRecord);          

 var memoryProxy  = new Ext.data.MemoryProxy(myData);              

 var storeDos = new Ext.data.Store({                                    
     reader : arrayReader,
     autoLoad: true,
     proxy  : memoryProxy
 });

I was thinking of putting this working copy somewhere in github, as I couldnt find anything with a memory proxy working


This is my simple Store. All in one and ready to load your object-array right away ;-)

Ext.define('MemoryStore', {
    extend: 'Ext.data.Store',

    requires: [
        'Ext.data.proxy.Memory'
    ],

    fields: [{name: 'company'}], 

    proxy: {
        type: 'memory'
    }
});

After creating the store, your can load json via loadData

var store = Ext.create("MemoryStore");
store.loadData([
   {company:"Skynet"},
   {company:"Rocket-Solutions"},
 ]);

 console.debug(store.first().get("name"));


In all the example they missed to put

autoLoad: true,
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜