Results 1 to 4 of 4

Thread: Create reader dynamically?

  1. #1
    Sencha User sb32's Avatar
    Join Date
    Sep 2007
    Posts
    66

    Default Create reader dynamically?

    Guys, please help. Just trying to figure out how I can create the reader hash dynamically, instead of hard coding {name: 'milk', mapping: 'milk'}

    Ideally, it would be a part of the Json response. Currently, the Json is:
    PHP Code:
    {"prices"=>{:milk=>"3.02", :bread=>"2.67"}} 
    If on the server side, I were to extend this to:
    PHP Code:
    {"products" => ["milk""bread"], "prices"=>{:milk=>"3.02", :bread=>"2.67"}} 
    How could I make the client side js build the readre based on the products array?

    Thanks so much

    PHP Code:
    <script type="text/javascript">
       
        function 
    getFieldValue(storerowIndexfieldName) {
            var 
    myDataRecord store.getAt(rowIndex);
            return 
    myDataRecord.get(fieldName);
        }
        function 
    display() {
            var 
    ds = new Ext.data.Store({
            
    proxy: new Ext.data.ScriptTagProxy({url'http://somewebsite.com/prices'}),
                
    reader: new Ext.data.JsonReader({
                    
    root'prices'
                
    },
            [
                {
    name'milk'mapping'milk'}
            ])
            });
               
    ds.load();
           
    document.getElementById('milk').innerHTML getFieldValue(ds0'milk');
        }
        
    </script>
    <body onLoad="display()">
        <div id="milk"></div>
    </body>
    </html> 

  2. #2
    Sencha User sb32's Avatar
    Join Date
    Sep 2007
    Posts
    66

    Default It's probably nasty, but it works..

    I'm all ears as to what's nasty about this but.. hey, I figured out a way to make it work

    Hope this helps the next person:
    json:
    PHP Code:
    (({products: [{product"milk"}, {product"bread"}], prices: [{milk"$3.45"bread"$2.83"}]})); 
    js:
    PHP Code:
    function display() {
        
    products = new Array();
        
    proxy = new Ext.data.ScriptTagProxy({url'http://somesite.com/cheap/prices'});
        
    productsReader = new Ext.data.JsonReader({root'products'}, [{name'product'}]);
        
    dsProducts = new Ext.data.Store({proxyproxy,readerproductsReader});
        
    dsProducts.on('load', function(storerecordsoptions){
            
    count dsProducts.getCount();
            for(var 
    i=0counti++ ){products.push({namedsProducts.getAt(i).get('product')});}
            
    pricesReader = new Ext.data.JsonReader({root'prices'},products);
            
    dsPrices = new Ext.data.Store({
                
    proxyproxy,
                
    readerpricesReader
            
    });
            
    dsPrices.on('load', function(storerecordsoptions){
                for(var 
    i=0counti++ ){
                    try {
    Ext.get('s1-' products[i]['name']).update(dsPrices.getAt(0).get(products[i]['name']));}
                    catch(
    err){}
                }
            });
            
    dsPrices.load();
        });
        
    dsProducts.load();


  3. #3
    Sencha User sb32's Avatar
    Join Date
    Sep 2007
    Posts
    66

    Default don't like it

    I don't like this, because it makes two json requests to the server instead of one.

    Any way to duplicate a data store without having it reconnect? I've looked at this quite a bit to no avail, please help

  4. #4
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •