2011-06-14 37 views
1

我正在使用rails 3.x實現extjs 3.2.1。我有一個JsonWriter,它通過Json存儲區寫入MySQL數據庫中的所有字段。有沒有辦法將記錄從一個Json商店複製到另一個JSON商店,但有一些不同的字段。ExtJS存儲 - 複製特定字段以存儲

這是我的嘗試:

var RecRecordDef = Ext.data.Record.create([ 
           {name: 'product_master_id'}, 
           {name: 'qty'}, 
           {name: 'stock_price'},{name: 'discount_rate'}, 
           {name: 'amount'} 
     ]); 

    salesbtn.on("click",function(){ 

       for(var cnt=1;cnt<=salestore.getCount();cnt++) 
       { 
        var rectmp= salestore.getAt(cnt); 

        var receiptrec= new RecRecordDef({ 
         product_master_id:rectmp.get('product_master_id'), 

         qty:rectmp.get('qty'), 
         stock_price:rectmp.get('stock_price'), 
         discount_rate:rectmp.get('discount_rate'), 
         amount:rectmp.get('amount') 
        }); 
        recstore.add(receiptrec); 

       } 
        recstore.save(); 

      }); 

其中,var recstore= Ext.StoreMgr.get('ReceiptStore');

但我正在逐漸瀏覽器的控制檯上的輸出如下: 遺漏的類型錯誤:不能調用方法「得到」的未定義

有什麼建議嗎?

在此先感謝!

回答

2

你必須嘗試這樣的事:

Ext.each(salesstore.getRange(), function(item, index, all){ 
    var receiptrec= new RecRecordDef({ 
        product_master_id: item.get('product_master_id'), 

        qty:item.get('qty'), 
        stock_price:item.get('stock_price'), 
        discount_rate:item.get('discount_rate'), 
        amount:item.get('amount') 
       }); 
       recstore.add(receiptrec); 
}, this); 
recstore.save(); 
+0

非常感謝!這解決了我的問題.. :-) – Rashmi 2011-06-17 04:03:36