跳至內容
選單
此問題已被標幟
1 回覆
4825 瀏覽次數

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.

相關帖文 回覆 瀏覽次數 活動
2
7月 22
12470
1
8月 19
4425
0
2月 17
2897
2
10月 22
5733
0
6月 22
2700