Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Globale Variable
#1
Hallo zusammen,

ich bin gerade am verzweifeln und finde keine Lösung.

Code:
let y=0;
var x=0;


function letztesY(Test){
    console.log("test: "+Test)
x=Test;

}


chrome.storage.local.get(null,  function(result)
{
    let anzahl=-1;
  
        //alle Keys mit "ETRetouren" anzeigen
        for (allKeys in result){
                                    if(allKeys.indexOf("ETRetoure")!=-1) { console.log(allKeys);
                                          
                                        chrome.storage.local.get(allKeys,  function(result){console.log(result);

                                            const myJSON = JSON.stringify(result);
                                 
                                        console.log(myJSON);
                                    let ZirETAuftrag=myJSON.substring(11,22);
                                 
                                    let Artikel=myJSON.substring(22,myJSON.indexOf(":")-1);
                               
                                    let Beschreibung=myJSON.substring(myJSON.indexOf(":")+2,myJSON.indexOf("||"));
                                                             
                                    let Menge=myJSON.substring(myJSON.indexOf("||")+2,myJSON.lastIndexOf('"'));

                                    document.querySelector("#Artikelauflistung").innerHTML+=`<tspan x="10" y="`+y+`">`+Menge+`</tspan>
                                   
                                                                                             <tspan x="43" Y="`+y+`">`+ZirETAuftrag+`</tspan>
                                                                                             <tspan x="123" y="`+y+`">`+Artikel+`</tspan>
                                                                                             <tspan x="203" y="`+y+`">`+Beschreibung+`</tspan>`;    
                                                                                             console.log(y);
                                                                                           
letztesY(y);
                                                                                             y+=20;                                                                                            
                                   
                                                                                            });
                                                                                          
                                                                           };
                                                                         
                                };
                            
                               }
                            // document.querySelector("#Artikelauflistung").innerHTML+=`<tspan X="10" y="`+(y=+60)+`">Datum"</tspan>
                            //                                                          <tspan x="150" y="`+(y=+60)+`">Mitarbeiter</tspan>`
                          
                            )


console.log(x);

ich möchte gerne den y Wert global bekommen und bekomme es nicht hin.
In oder aus der Function letztesY wird im log die richtigen werte angezeigt, doch im letzten bleibt die x Variable auf "0" wenn ich sie ganz untem im Code ausgeben möchte.
Wo ist der Fehler? Ich sehe es nicht

Gruß
Zitieren


Nachrichten in diesem Thema
Globale Variable - von Oly - 06.05.2023, 21:04
RE: Globale Variable - von Oly - 07.05.2023, 15:37
RE: Globale Variable - von rzscout - 08.05.2023, 02:22
RE: Globale Variable - von Oly - 08.05.2023, 07:14
RE: Globale Variable - von rzscout - 08.05.2023, 11:41
RE: Globale Variable - von Oly - 08.05.2023, 13:34
RE: Globale Variable - von Oly - 09.05.2023, 10:03
RE: Globale Variable - von rzscout - 09.05.2023, 18:24
RE: Globale Variable - von Oly - 09.05.2023, 18:38
RE: Globale Variable - von AndreasB - 10.05.2023, 07:59

Gehe zu:


Benutzer, die gerade dieses Thema anschauen:
1 Gast/Gäste