Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
joo.classLoader.prepare("package ext.config",/* {*/

 * Data reader class to create an Array of <a href=""></a> objects from a JSON packet based on mappings in a provided <a href=""></a> constructor.
 <p>Example code:</p><pre><code>var myReader = new{
 // metadata configuration options:
 <a href="output/">idProperty</a>: 'id'
 <a href="output/">root</a>: 'rows',
 <a href="output/">totalProperty</a>: 'results',
 <a href="output/"></a>: "msg"  // The element within the response that provides a user-feedback message (optional)

 // the fields config option will internally create an <a href=""></a>
 // constructor that provides mapping for reading the record data objects
 <a href="output/">fields</a>: [
 // map Record's 'firstname' field to data object's key of same name
 {name: 'name', mapping: 'firstname'},
 // map Record's 'job' field to data object's 'occupation' key
 {name: 'job', mapping: 'occupation'}
 </code></pre><p>This would consume a JSON data object of the form:</p><pre><code>{
 results: 2000, // Reader's configured <a href="output/">totalProperty</a>
 rows: [        // Reader's configured <a href="output/">root</a>
 // record data objects:
 { <a href="output/">id</a>: 1, firstname: 'Bill', occupation: 'Gardener' },
 { <a href="output/">id</a>: 2, firstname: 'Ben' , occupation: 'Horticulturalist' },
 </code></pre><p style="font-weight: bold"><u>Automatic configuration using metaData</u></p><p>It is possible to change a JsonReader's metadata at any time by including a <b><tt>metaData</tt></b> property in the JSON data object. If the JSON data object has a <b><tt>metaData</tt></b> property, a <a href="">Store</a> object using this Reader will reconfigure itself to use the newly provided field definition and fire its <a href="output/">metachange</a> event. The metachange event handler may interrogate the <b><tt>metaData</tt></b> property to perform any configuration required.</p><p>Note that reconfiguring a Store potentially invalidates objects which may refer to Fields or Records which no longer exist.</p><p>To use this facility you would create the JsonReader like this:</p><pre><code>var myReader = new;
 </code></pre><p>The first data packet from the server would configure the reader by containing a <b><tt>metaData</tt></b> property <b>and</b> the data. For example, the JSON data object might take the form:</p><pre><code>{
 metaData: {
 "<a href="output/">idProperty</a>": "id",
 "<a href="output/">root</a>": "rows",
 "<a href="output/">totalProperty</a>": "results"
 "<a href="output/">successProperty</a>": "success",
 "<a href="output/">fields</a>": [
 {"name": "name"},
 {"name": "job", "mapping": "occupation"}
 // used by store to set its sortInfo
 "field": "name",
 "direction": "ASC"
 // <a href="Ext.PagingToolbar.html">paging data</a> (if applicable)
 "start": 0,
 "limit": 2,
 // custom property
 "foo": "bar"
 // Reader's configured <a href="output/">successProperty</a>
 "success": true,
 // Reader's configured <a href="output/">totalProperty</a>
 "results": 2000,
 // Reader's configured <a href="output/">root</a>
 // (this data simulates 2 results <a href="Ext.PagingToolbar.html">per page</a>)
 "rows": [ // <b>&#42;Note:</b> this must be an Array
 { "id": 1, "name": "Bill", "occupation": "Gardener" },
 { "id": 2, "name":  "Ben", "occupation": "Horticulturalist" }
 </code></pre><p>The <b><tt>metaData</tt></b> property in the JSON data object should contain:</p><div class="mdetail-params"><ul><li>any of the configuration options for this class</li><li>a <b><tt><a href="output/">fields</a></tt></b> property which the JsonReader will use as an argument to the <a href="output/">data Record create method</a> in order to configure the layout of the Records it will produce.</li><li>a <b><tt><a href="output/">sortInfo</a></tt></b> property which the JsonReader will use to set the <a href=""></a>'s <a href="output/">sortInfo</a> property</li><li>any custom properties needed</li></ul></div>
 * <p>This class serves as a
 * typed config object for constructor of class JsonReader.</p>
 * <p>Copyright &#169; 2011 Sencha Inc.</p>
 * @see
"public class jsonreader extends ext.config.datareader",3,function($$private){var $1=ext.config;return[ 

  "public function jsonreader",function jsonreader(config/*:Object = null*/) {if(arguments.length<=0)config=null;


   [id] Name of the property within a row object that contains a record identifier value. Defaults to <tt>id</tt>
  "public native function get idProperty"/*():String*/,

   * @private
  "public native function set idProperty"/*(value:String):void*/,

   [undefined] <b>Required</b>. The name of the property which contains the Array of row objects. Defaults to <tt>undefined</tt>. An exception will be thrown if the root property is undefined. The data packet value for this property should be an empty array to clear the data or show no data.
  "public native function get root"/*():String*/,

   * @private
  "public native function set root"/*(value:String):void*/,

   [success] Name of the property from which to retrieve the success attribute. Defaults to <tt>success</tt>. See <a href=""></a>.<a href="output/">exception</a> for additional information.
  "public native function get successProperty"/*():String*/,

   * @private
  "public native function set successProperty"/*(value:String):void*/,

   [total] Name of the property from which to retrieve the total number of records in the dataset. This is only needed if the whole dataset is not passed in one go, but is being paged from the remote server. Defaults to <tt>total</tt>.
  "public native function get totalProperty"/*():String*/,

   * @private
  "public native function set totalProperty"/*(value:String):void*/,

undefined];},[],["ext.config.datareader"], "0.8.0", "2.0.13"
New to GrepCode? Check out our FAQ X