1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.proxy.Memory'>/**
2 </span> * @author Ed Spencer
3 * @class Ext.data.proxy.Memory
4 * @extends Ext.data.proxy.Client
6 * <p>In-memory proxy. This proxy simply uses a local variable for data storage/retrieval, so its contents are lost on
7 * every page refresh.</p>
9 * <p>Usually this Proxy isn't used directly, serving instead as a helper to a {@link Ext.data.Store Store} where a
10 * reader is required to load data. For example, say we have a Store for a User model and have some inline data we want
11 * to load, but this data isn't in quite the right format: we can use a MemoryProxy with a JsonReader to read it into
12 * our Store:</p>
14 <pre><code>
15 //this is the model we will be using in the store
17 extend: 'Ext.data.Model',
19 {name: 'id', type: 'int'},
20 {name: 'name', type: 'string'},
21 {name: 'phone', type: 'string', mapping: 'phoneNumber'}
25 //this data does not line up to our model fields - the phone field is called phoneNumber
31 phoneNumber: '555 1234'
36 phoneNumber: '666 1234'
41 //note how we set the 'root' in the reader to match the data structure above
42 var store = new Ext.data.Store({
54 </code></pre>
56 Ext.define('Ext.data.proxy.Memory', {
57 extend: 'Ext.data.proxy.Client',
58 alias: 'proxy.memory',
59 alternateClassName: 'Ext.data.MemoryProxy',
61 <span id='Ext-data.proxy.Memory-cfg-data'> /**
62 </span> * @cfg {Array} data Optional array of Records to load into the Proxy
65 constructor: function(config) {
66 this.callParent([config]);
68 //ensures that the reader has been instantiated properly
69 this.setReader(this.reader);
72 <span id='Ext-data.proxy.Memory-method-read'> /**
73 </span> * Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present
74 * @param {Ext.data.Operation} operation The read Operation
75 * @param {Function} callback The callback to call when reading has completed
76 * @param {Object} scope The scope to call the callback function in
78 read: function(operation, callback, scope) {
80 reader = me.getReader(),
81 result = reader.read(me.data);
83 Ext.apply(operation, {
87 operation.setCompleted();
88 operation.setSuccessful();
89 Ext.callback(callback, scope || me, [operation]);
94 </pre></pre></body></html>