Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3843 Vistas

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
Descartar
Autor Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
jun 25
343
1
jun 25
654
1
jun 25
649
1
may 25
1206
0
mar 25
677