2011-06-14 17 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