Skip to Content
Menu
This question has been flagged
1 Reply
3392 Views

Hello guys,

I really don't understand this new problem in Javascript.

I'm in the javascript function update_payment_summary in the point of sale.


This one works well :

var currentOrder = this.pos.get('selectedOrder');
var plines = currentOrder.get('paymentLines').models;

for (var i = 0; i < plines.length; i++) {
    var message = plines[i].get_type();
    console.log('payment_method ' + message +' et le i est : ' + i);
}

The log displays :  "payment_method cash et le i est : 0"


This one doesn't work ??????? :

var currentOrder = this.pos.get('selectedOrder');
var plines = currentOrder.get('paymentLines').models;

var i = 0;
var message = plines[i].get_type();
console.log('payment_method ' + message +' et le i est : ' + i); }

I get this error :  TypeError: plines[i] is undefined



I'm crazy or what?

Thanks to help

Avatar
Discard
Author Best Answer

I have found my error.

When the point of sale load at the beginning, the function update_payment_summary is called.

This first time that the function is called, there is no paymentlines.

So my plines variable is undefined.

The using of the for statement is not the problem.

This one works :

                if (plines.length > 0) {
                           var i = 0;  
                      var mes = plines[i].get_type();
                       console.log('payment_method' + mes +'et le i est : ' + i);
                }


Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
127
2
Nov 24
84
1
Oct 24
264
0
Sep 24
213
2
Sep 24
648