Array3.html 3.4 KB

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