Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Umělá inteligence
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
2 Odpovědi
7943 Zobrazení
Avatar
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
Avatar
Zrušit
Avatar
Shawn Varghese
Nejlepší odpověď

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
Avatar
Zrušit
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.

Avatar
Rui Franco
Autor Nejlepší odpověď

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
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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