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

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

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

Try to change this:

var def = new $.Deferred();

return def;

to this:

var def = $.Deferred();

return def.promise();

Аватар
Відмінити
Автор

Thanks, but it did no good.

Related Posts Відповіді Переглядів Дія
2
лип. 22
12414
1
серп. 19
4358
0
лют. 17
2842
2
жовт. 22
5718
0
черв. 22
2671