콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
4875 화면

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
12560
1
8월 19
4477
0
2월 17
2942
2
10월 22
5783
0
6월 22
2736