Przejdź do zawartości
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Artificial Intelligence
    • IoT
    • VoIP
    • Wiedza
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Javascript query [ deferred values ] - how to get them?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
2 Odpowiedzi
7950 Widoki
Awatar
Rui Franco

Taking in consideration the following code, how can I populate the 'lat' and 'lng' variables? I can only get a value inside the "query". :|

 

var lat=0;

var lng=0

if (coords){
                var coords_obj = new openerp.Model('gps_base.coords');
                coords_obj.query(['latitude_aux', 'longitude_aux'])
                     .filter([['id', '=', coords]])
                     .limit(1)
                     .all().then(function (result) {
                            _.each(result, function(item) {
                                lat=item.latitude_aux;
                                lng=item.longitude_aux;
                            });
                        });
                alert(lat); //shows 'undefined'
            }

0
Awatar
Odrzuć
Awatar
Shawn Varghese
Najlepsza odpowiedź

From my understanding of jQuery, .then() is an asynchronous call. This means that, the .then() function will be called after the coords_obj query returns a result, but any code outside will be carried out without waiting for query result.

The following line:

alert(lat);

, is outside the .then() function. Therefore, it gets called before the query returns a result. But the wierd part is that it doesn't even show the default value 0 . I noticed that console.log(lat) works in such cases, instead of using alert(lat).

Try modifying the code like this:

 

if (coords){

                var coords_obj = new openerp.Model('gps_base.coords');
                coords_obj.query(['latitude_aux', 'longitude_aux'])
                     .filter([['id', '=', coords]])
                     .limit(1)
                     .all().then(function (result) {
                            _.each(result, function(item) {
                                lat=item.latitude_aux;
                                lng=item.longitude_aux;

self.latLngFunction(lat,lng); //This way, lat and lng are displayed correctly


                            });
                        });
            }
,

// After the above function body, create a new function similar to the one below:

latLngFunction:function(lat,lng)
        {
            console.log("Latitude",lat); //
You can view this result in your browser console
            console.log("Longitute",lng);
            //
OR
            alert(lat); //Now the alert should display a proper value.
            alert(lng);
        },

 

0
Awatar
Odrzuć
Shawn Varghese

Please let me know if this doesn't work.

Shawn Varghese

The deferred and resolve calls that you have used seem correct. This is the cleaner way to do it. However, I have faced issues with using these calls in the past - I think I am missing something as well. Can you try using console.log(query_res.latitude_aux); instead of alert(query_res.latitude_aux), just to confirm that the issue does not reside with the alert() dialog.

Awatar
Rui Franco
Autor Najlepsza odpowiedź

Many thanks Swahn but no, it didn't work. You did set me in the proper direction and, after looking for widget code in the Odoo modules, I eventually came to write this:

          function get_coordinates(coords_id){

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

 

            if (coords){
                query_res=get_coordinates(coords);
                alert(query_res.latitude_aux);
            }

 

But, unfortunately, I never get a proper value. I'm lost. It seems no matter what example I follow, it never works. Has to be something really silly I am missing here... :(

0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now