4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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
21 * In-memory proxy. This proxy simply uses a local variable for data storage/retrieval, so its contents are lost on
24 * Usually this Proxy isn't used directly, serving instead as a helper to a {@link Ext.data.Store Store} where a reader
25 * is required to load data. For example, say we have a Store for a User model and have some inline data we want to
26 * load, but this data isn't in quite the right format: we can use a MemoryProxy with a JsonReader to read it into our
29 * //this is the model we will be using in the store
30 * Ext.define('User', {
31 * extend: 'Ext.data.Model',
33 * {name: 'id', type: 'int'},
34 * {name: 'name', type: 'string'},
35 * {name: 'phone', type: 'string', mapping: 'phoneNumber'}
39 * //this data does not line up to our model fields - the phone field is called phoneNumber
45 * phoneNumber: '555 1234'
50 * phoneNumber: '666 1234'
55 * //note how we set the 'root' in the reader to match the data structure above
56 * var store = Ext.create('Ext.data.Store', {
69 Ext.define('Ext.data.proxy.Memory', {
70 extend: 'Ext.data.proxy.Client',
71 alias: 'proxy.memory',
72 alternateClassName: 'Ext.data.MemoryProxy',
74 <span id='Ext-data-proxy-Memory-cfg-data'> /**
75 </span> * @cfg {Ext.data.Model[]} data
76 * Optional array of Records to load into the Proxy
79 constructor: function(config) {
80 this.callParent([config]);
82 //ensures that the reader has been instantiated properly
83 this.setReader(this.reader);
86 <span id='Ext-data-proxy-Memory-method-read'> /**
87 </span> * Reads data from the configured {@link #data} object. Uses the Proxy's {@link #reader}, if present.
88 * @param {Ext.data.Operation} operation The read Operation
89 * @param {Function} callback The callback to call when reading has completed
90 * @param {Object} scope The scope to call the callback function in
92 read: function(operation, callback, scope) {
94 reader = me.getReader(),
95 result = reader.read(me.data);
97 Ext.apply(operation, {
101 operation.setCompleted();
102 operation.setSuccessful();
103 Ext.callback(callback, scope || me, [operation]);