Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3864 Widoki

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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);
                }


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lip 25
261
0
cze 25
486
1
cze 25
711
1
cze 25
735
1
maj 25
1286