Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
4100 Vistas

I need a little help on Odoo widget. I have this in js file...

_format: function (row_data, options) {

this.session = session;

if (!row_data[this.id] || !row_data[this.id].value) {

return '';

}

var arraygiven = [];

new model('sale.order.line').query(['order_id']).filter([['product_id', '=', row_data[this.id].value]]).all().then(function (records) {

for(var i = 0, len = records.length; i < len; i++){

arraygiven.push(records[i].order_id[1]);

}

//console.log(arraygiven);//arraygiven is shown in console

});

//console.log(arraygiven); //arraygiven is not shown in console

return QWeb.render('producthistorylist', {widget: this, saleorderlinenum: arraygiven});

}

How can i stop further process until i get the value from ajax request i.e. in "arraygiven" in above code? I have to return Qweb.render(....) after the value of arraygiven is received from ajax request?

Avatar
Descartar
Mejor respuesta

You have a problem with the function itself. This function is designed to format the data in the client, not to get more that from the server. If you need more data to format it correctly you will need to find the correct function to load all the data from the server and call the format function once all data is the client.

About the Deffered idea, it works, but it doesnt work. Looks like you dont understand them either. The return you have in the "then" function is not the return of the "_format" function. In your code the "_format" function don't have  a return value.

As i said it work, if you console.log(Qweb....) it will print, but not place in the document.

Avatar
Descartar
Mejor respuesta

=======================

Below Code May Help You

=======================

_format: function (row_data, options) {

this.session = session;

if (!row_data[this.id] || !row_data[this.id].value) {

return '';

}

var self = this;

var call_done = $.Deferred();

var arraygiven = [];

new model('sale.order.line').query(['order_id']).filter([['product_id', '=', row_data[this.id].value]]).all().then(function (records) {

for(var i = 0, len = records.length; i < len; i++){

arraygiven.push(records[i].order_id[1]);

}

call_done.resolve(arraygiven);

});

call_done.then(function (values) {

console.log(values); // YOUR VALUES(arraygiven) ARE COME HERE

return QWeb.render('producthistorylist', {widget: self, saleorderlinenum: values});

});

}

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
may 23
6329
1
jul 16
3393
1
jun 23
2325
0
ene 21
2182
2
dic 19
7750