Array3.html
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-data-reader-Array-method-constructor'><span id='Ext-data-reader-Array'>/**
</span></span> * @author Ed Spencer
* @class Ext.data.reader.Array
*
* <p>Data reader class to create an Array of {@link Ext.data.Model} objects from an Array.
* Each element of that Array represents a row of data fields. The
* fields are pulled into a Record object using as a subscript, the <code>mapping</code> property
* of the field definition if it exists, or the field's ordinal position in the definition.</p>
*
* <p><u>Example code:</u></p>
*
<pre><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 myReader = new Ext.data.reader.Array({
model: 'Employee'
}, Employee);
</code></pre>
*
* <p>This would consume an Array like this:</p>
*
<pre><code>
[ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
</code></pre>
*
* @constructor
* Create a new ArrayReader
* @param {Object} meta Metadata configuration options.
*/
Ext.define('Ext.data.reader.Array', {
extend: 'Ext.data.reader.Json',
alternateClassName: 'Ext.data.ArrayReader',
alias : 'reader.array',
// For Array Reader, methods in the base which use these properties must not see the defaults
totalProperty: undefined,
successProperty: undefined,
<span id='Ext-data-reader-Array-method-createFieldAccessExpression'> /**
</span> * @private
* Returns an accessor expression for the passed Field from an Array using either the Field's mapping, or
* its ordinal position in the fields collsction as the index.
* This is used by buildExtractors to create optimized on extractor function which converts raw data into model instances.
*/
createFieldAccessExpression: function(field, fieldVarName, dataName) {
// In the absence of a mapping property, use the original ordinal position
// at which the Model inserted the field into its collection.
var index = (field.mapping == null) ? field.originalIndex : field.mapping,
result;
if (typeof index === 'function') {
result = fieldVarName + '.mapping(' + dataName + ', this)';
} else {
if (isNaN(index)) {
index = '"' + index + '"';
}
result = dataName + "[" + index + "]";
}
return result;
}
});
</pre>
</body>
</html>