2016-06-16 21 views
3

を取得し、この機能はPaymentScreenWidgetの一部です。 今、注文ラインから商品を取り寄せたいと思います。Odoo POSは私がPoint_Of_Saleに<strong>update_payment_summary</strong>機能を更新していますオーダーライン製品

私は

var order = this.pos.get('selectedOrder'); 
var orderlines = order.get('orderLines').models; 

と試みたが、私は注文ラインを印刷するとき、私は、私はすべてのオーダーラインの製品オブジェクトを取得する方法[オブジェクトのオブジェクト]

どれでもアイデアを得ますか?

答えて

2

は、はい、それはオブジェクトを示していた理由がある製品のリストでループを繰り返すことができます。

OrderlineCollectionの定義。

module.OrderlineCollection = Backbone.Collection.extend({ 
     model: module.Orderline, 
}); 

オーダーモデルのオーダーライン定義。

orderLines:  new module.OrderlineCollection() 

あなたは、コードの上に観察するのであれば、それはオーダーラインがOrderlineCollectionモデルのオブジェクトであり、あなたは次モデルからの注文ラインを取得しながら、それはあなたにOrderlineCollectionのオブジェクトを与えるだろうことを示しています。

オブジェクトの内部にあるものを識別するために、そのオブジェクトを反復処理するか、そのオブジェクトからキー値を出力することができます。

alert(orderline.forEach(function(k,v){k + " => + v})); 

また、オーダーラインをループすることもできます。

for (line in orderline){ 
    alert(line.product_id); 
} 
1

get_orderlines()機能を使用して、特定のOrderからOrderLinesを取得します。

var order = this.pos.get_order(); 
var products = _.map(order.get_orderlines(), function (line) {return line.product; }); 
console.log(products); 

ここでは、ユーザーUnderscore.jsは製品のリストを作成します。

あなたのような、

for(var i =0; i < products.length; i++) 
    console.log(products[i].id); 
関連する問題