Odoo Help

0

Javascript: getting the value out of a "resolve"

By
Rui Franco
on 2/28/15, 1:16 PM 691 views

I'm trying to query a database from inside a function and, then, use the values I get. However, although the query is performed appropriately and the values are correct, I am not able to return them.

Does anyone know how to fix the code below? :|

function get_coordinates(coords_id){
                var def = new $.Deferred();
                new instance.web.Model("gps_base.coords")
                    .query(['latitude_aux','longitude_aux'])
                    .filter([["id", "=", coords_id]])
                    .first()
                    .then(function(result) {
                        if(!result || result.length === 0){
                            def.reject();
                            return;
                        }else{
                            //this works!
                            //alert(result['latitude_aux']); 
                            def.resolve(result);
                        }
                    });
                    
                //this is "just" Object...
                //alert(def);
                return def;
            }

0
tolstoj
On 3/1/15, 5:02 AM

Try to change this:

var def = new $.Deferred();

return def;

to this:

var def = $.Deferred();

return def.promise();

Thanks, but it did no good.

Rui Franco
on 3/1/15, 2:40 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 2/28/15, 1:16 PM
Seen: 691 times
Last updated: 3/16/15, 8:10 AM