XmlStore.html 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-XmlStore'>/**
  19. </span> * @author Ed Spencer
  20. * &lt;p&gt;Small helper class to make creating {@link Ext.data.Store}s from XML data easier.
  21. * A XmlStore will be automatically configured with a {@link Ext.data.reader.Xml}.&lt;/p&gt;
  22. * &lt;p&gt;A store configuration would be something like:&lt;pre&gt;&lt;code&gt;
  23. var store = new Ext.data.XmlStore({
  24. // store configs
  25. storeId: 'myStore',
  26. url: 'sheldon.xml', // automatically configures a HttpProxy
  27. // reader configs
  28. record: 'Item', // records will have an &quot;Item&quot; tag
  29. idPath: 'ASIN',
  30. totalRecords: '@TotalResults'
  31. fields: [
  32. // set up the fields mapping into the xml doc
  33. // The first needs mapping, the others are very basic
  34. {name: 'Author', mapping: 'ItemAttributes &gt; Author'},
  35. 'Title', 'Manufacturer', 'ProductGroup'
  36. ]
  37. });
  38. * &lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
  39. * &lt;p&gt;This store is configured to consume a returned object of the form:&lt;pre&gt;&lt;code&gt;
  40. &amp;#60?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  41. &amp;#60ItemSearchResponse xmlns=&quot;http://webservices.amazon.com/AWSECommerceService/2009-05-15&quot;&gt;
  42. &amp;#60Items&gt;
  43. &amp;#60Request&gt;
  44. &amp;#60IsValid&gt;True&amp;#60/IsValid&gt;
  45. &amp;#60ItemSearchRequest&gt;
  46. &amp;#60Author&gt;Sidney Sheldon&amp;#60/Author&gt;
  47. &amp;#60SearchIndex&gt;Books&amp;#60/SearchIndex&gt;
  48. &amp;#60/ItemSearchRequest&gt;
  49. &amp;#60/Request&gt;
  50. &amp;#60TotalResults&gt;203&amp;#60/TotalResults&gt;
  51. &amp;#60TotalPages&gt;21&amp;#60/TotalPages&gt;
  52. &amp;#60Item&gt;
  53. &amp;#60ASIN&gt;0446355453&amp;#60/ASIN&gt;
  54. &amp;#60DetailPageURL&gt;
  55. http://www.amazon.com/
  56. &amp;#60/DetailPageURL&gt;
  57. &amp;#60ItemAttributes&gt;
  58. &amp;#60Author&gt;Sidney Sheldon&amp;#60/Author&gt;
  59. &amp;#60Manufacturer&gt;Warner Books&amp;#60/Manufacturer&gt;
  60. &amp;#60ProductGroup&gt;Book&amp;#60/ProductGroup&gt;
  61. &amp;#60Title&gt;Master of the Game&amp;#60/Title&gt;
  62. &amp;#60/ItemAttributes&gt;
  63. &amp;#60/Item&gt;
  64. &amp;#60/Items&gt;
  65. &amp;#60/ItemSearchResponse&gt;
  66. * &lt;/code&gt;&lt;/pre&gt;
  67. * An object literal of this form could also be used as the {@link #cfg-data} config option.&lt;/p&gt;
  68. * &lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; This class accepts all of the configuration options of
  69. * &lt;b&gt;{@link Ext.data.reader.Xml XmlReader}&lt;/b&gt;.&lt;/p&gt;
  70. */
  71. Ext.define('Ext.data.XmlStore', {
  72. extend: 'Ext.data.Store',
  73. alias: 'store.xml',
  74. requires: [
  75. 'Ext.data.proxy.Ajax',
  76. 'Ext.data.reader.Xml',
  77. 'Ext.data.writer.Xml'
  78. ],
  79. constructor: function(config){
  80. config = Ext.apply({
  81. proxy: {
  82. type: 'ajax',
  83. reader: 'xml',
  84. writer: 'xml'
  85. }
  86. }, config);
  87. this.callParent([config]);
  88. }
  89. });</pre>
  90. </body>
  91. </html>