Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
4114 Переглядів

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?

Аватар
Відмінити
Найкраща відповідь

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.

Аватар
Відмінити
Найкраща відповідь

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

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

});

}

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
трав. 23
6390
1
лип. 16
3435
1
черв. 23
2360
0
січ. 21
2200
2
груд. 19
7808