4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-proxy-Memory'>/**
19 </span> * @author Ed Spencer
20 * @class Ext.data.proxy.Memory
21 * @extends Ext.data.proxy.Client
23 * <p>In-memory proxy. This proxy simply uses a local variable for data storage/retrieval, so its contents are lost on
24 * every page refresh.</p>
26 * <p>Usually this Proxy isn't used directly, serving instead as a helper to a {@link Ext.data.Store Store} where a
27 * reader is required to load data. For example, say we have a Store for a User model and have some inline data we want
28 * to load, but this data isn't in quite the right format: we can use a MemoryProxy with a JsonReader to read it into
29 * our Store:</p>
31 <pre><code>
32 //this is the model we will be using in the store
34 extend: 'Ext.data.Model',
36 {name: 'id', type: 'int'},
37 {name: 'name', type: 'string'},
38 {name: 'phone', type: 'string', mapping: 'phoneNumber'}
42 //this data does not line up to our model fields - the phone field is called phoneNumber
48 phoneNumber: '555 1234'
53 phoneNumber: '666 1234'
58 //note how we set the 'root' in the reader to match the data structure above
59 var store = new Ext.data.Store({
71 </code></pre>
73 Ext.define('Ext.data.proxy.Memory', {
74 extend: 'Ext.data.proxy.Client',
75 alias: 'proxy.memory',
76 alternateClassName: 'Ext.data.MemoryProxy',
78 <span id='Ext-data-proxy-Memory-cfg-data'> /**
79 </span> * @cfg {Array} data Optional array of Records to load into the Proxy
82 constructor: function(config) {
83 this.callParent([config]);
85 //ensures that the reader has been instantiated properly
86 this.setReader(this.reader);
89 <span id='Ext-data-proxy-Memory-method-read'> /**
90 </span> * Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present
91 * @param {Ext.data.Operation} operation The read Operation
92 * @param {Function} callback The callback to call when reading has completed
93 * @param {Object} scope The scope to call the callback function in
95 read: function(operation, callback, scope) {
97 reader = me.getReader(),
98 result = reader.read(me.data);
100 Ext.apply(operation, {
104 operation.setCompleted();
105 operation.setSuccessful();
106 Ext.callback(callback, scope || me, [operation]);