JsonStore.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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-JsonStore'>/**
  19. </span> * @author Ed Spencer
  20. *
  21. * &lt;p&gt;Small helper class to make creating {@link Ext.data.Store}s from JSON data easier.
  22. * A JsonStore will be automatically configured with a {@link Ext.data.reader.Json}.&lt;/p&gt;
  23. *
  24. * &lt;p&gt;A store configuration would be something like:&lt;/p&gt;
  25. *
  26. &lt;pre&gt;&lt;code&gt;
  27. var store = new Ext.data.JsonStore({
  28. // store configs
  29. storeId: 'myStore',
  30. proxy: {
  31. type: 'ajax',
  32. url: 'get-images.php',
  33. reader: {
  34. type: 'json',
  35. root: 'images',
  36. idProperty: 'name'
  37. }
  38. },
  39. //alternatively, a {@link Ext.data.Model} name can be given (see {@link Ext.data.Store} for an example)
  40. fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
  41. });
  42. &lt;/code&gt;&lt;/pre&gt;
  43. *
  44. * &lt;p&gt;This store is configured to consume a returned object of the form:&lt;pre&gt;&lt;code&gt;
  45. {
  46. images: [
  47. {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)},
  48. {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)}
  49. ]
  50. }
  51. &lt;/code&gt;&lt;/pre&gt;
  52. *
  53. * &lt;p&gt;An object literal of this form could also be used as the {@link #cfg-data} config option.&lt;/p&gt;
  54. */
  55. Ext.define('Ext.data.JsonStore', {
  56. extend: 'Ext.data.Store',
  57. alias: 'store.json',
  58. requires: [
  59. 'Ext.data.proxy.Ajax',
  60. 'Ext.data.reader.Json',
  61. 'Ext.data.writer.Json'
  62. ],
  63. constructor: function(config) {
  64. config = Ext.apply({
  65. proxy: {
  66. type : 'ajax',
  67. reader: 'json',
  68. writer: 'json'
  69. }
  70. }, config);
  71. this.callParent([config]);
  72. }
  73. });</pre>
  74. </body>
  75. </html>