Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. Mehrere Objekte mit deren Datenpunkten in VIS Tabelle

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Mehrere Objekte mit deren Datenpunkten in VIS Tabelle

    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Snopy_16 @OliverIO last edited by

      @oliverio
      Danke, werd ich dann gleich mal probieren

      1 Reply Last reply Reply Quote 0
      • S
        Snopy_16 @OliverIO last edited by

        @oliverio

        const persons = $('unifi.0.default.clients.*.is_online').toArray();
        const jsonId = '0_userdata.0.Unifi.Clients';
        
        function checkOnline() {
            let list = [];
            persons.forEach(function (id) {
                let obj = {
                    online: getState(id).val,
                    Name: getState(id.replace('.is_online', '.name')).val,
                    IP: getState(id.replace('.is_online', '.ip')).val,
        			zuletzt: getState(id.replace('.is_online', '.last_seen_by_uap')).val,
                    //Mac: getState(id.replace('.is_online','.mac')).val
                };    
                list.push(obj);
            });
            setState(jsonId, JSON.stringify(list), true);
        }
        
        on({id: persons, change: "ne"}, function(obj) {
            checkOnline();
        });
        
        checkOnline();
        

        Leider funktioniert diese sort-function bei mir nicht
        Da steht irgendwas von list not defined

        Sorry, aber bin in Javascript ein ziemliches Greenhorn.

        OliverIO 1 Reply Last reply Reply Quote 0
        • OliverIO
          OliverIO @Snopy_16 last edited by OliverIO

          @snopy_16

          Genaue Fehlermeldung bitte kopieren.
          Wo sind jetzt die sortierfunktionen?
          Und du hast die Schreibweise von ip und Name verändert. Das muss in den sortierfunktionen angepasst werden

          S 1 Reply Last reply Reply Quote 0
          • S
            Snopy_16 @OliverIO last edited by

            @oliverio

            Ich checks nicht

            const persons = $('unifi.0.default.clients.*.is_online').toArray();
            const jsonId = '0_userdata.0.Unifi.Clients';
            
            function checkOnline() {
                let list = [];
                persons.forEach(function (id) {
                    let obj = {
                        online: getState(id).val,
                        Name: getState(id.replace('.is_online', '.name')).val,
                        IP: getState(id.replace('.is_online', '.ip')).val,
            			zuletzt: getState(id.replace('.is_online', '.last_seen_by_uap')).val,
                        //Mac: getState(id.replace('.is_online','.mac')).val
                    };    
                    list.push(obj);
                });
                setState(jsonId, JSON.stringify(list), true);
            }
            
            on({id: persons, change: "ne"}, function(obj) {
                checkOnline();
            });
            
            
            function sortIP(a,b) {
                return a.IP<b.IP
            }
            function sortName(a,b) {
                return a.Name<b.Name
            }
            setState(jsonId, JSON.stringify(list.sort(sortName), true);
             
            
            
            checkOnline();
            

            Fehlermeldung:

            javascript.0
            2025-02-15 13:18:32.659	error	at processImmediate (node:internal/timers:485:21)
            
            javascript.0
            2025-02-15 13:18:32.659	error	at Immediate._onImmediate (/opt/iobroker/node_modules/iobroker.javascript/main.js:1732:17)
            
            javascript.0
            2025-02-15 13:18:32.659	error	at /opt/iobroker/node_modules/iobroker.javascript/main.js:2322:17
            
            javascript.0
            2025-02-15 13:18:32.659	error	at prepareScript (/opt/iobroker/node_modules/iobroker.javascript/main.js:2224:37)
            
            javascript.0
            2025-02-15 13:18:32.659	error	at createVM (/opt/iobroker/node_modules/iobroker.javascript/main.js:1956:21)
            
            javascript.0
            2025-02-15 13:18:32.659	error	at new Script (node:vm:117:7)
            
            javascript.0
            2025-02-15 13:18:32.659	error	SyntaxError: missing ) after argument list
            
            javascript.0
            2025-02-15 13:18:32.659	error	^
            
            javascript.0
            2025-02-15 13:18:32.659	error	setState(jsonId, JSON.stringify(list.sort(sortName), true);
            
            javascript.0
            2025-02-15 13:18:32.659	error	script.js.Mein_Ordner.Unifi.Unifi_Geräte compile failed: at script.js.Mein_Ordner.Unifi.Unifi_Geräte:31
            
            javascript.0
            2025-02-15 13:18:32.658	info	Start JavaScript script.js.Mein_Ordner.Unifi.Unifi_Geräte (Javascript/js)
            
            javascript.0
            2025-02-15 13:18:32.568	info	Stopping script script.js.Mein_Ordner.Unifi.Unifi_Geräte
            
            OliverIO 1 Reply Last reply Reply Quote 0
            • OliverIO
              OliverIO @Snopy_16 last edited by

              @snopy_16

              Jetzt ist es klar. Du sollst deine bisherige Zeile
              setState durch die von mir geposteten Zeilen ersetzen.
              an der Stelle, wo du es hin kopiert hast, gibt es in der Tat kein List

              Warum steht hier
              https://javascript.info/closure

              S 1 Reply Last reply Reply Quote 0
              • S
                Snopy_16 @OliverIO last edited by

                @OliverIO
                Sorry, kein Fehler aber auch keine Sortierung im json

                const persons = $('unifi.0.default.clients.*.is_online').toArray();
                const jsonId = '0_userdata.0.Unifi.Clients';
                
                function checkOnline() {
                    let list = [];
                    persons.forEach(function (id) {
                        let obj = {
                            online: getState(id).val,
                            name: getState(id.replace('.is_online', '.name')).val,
                            ip: getState(id.replace('.is_online', '.ip')).val,
                			zuletzt: getState(id.replace('.is_online', '.last_seen_by_uap')).val,
                            //Mac: getState(id.replace('.is_online','.mac')).val
                        };    
                        list.push(obj);
                    });
                    
                //setState(jsonId, JSON.stringify(list), true);
                
                function sortIP(a,b) {
                return a.ip<b.ip
                }
                function sortName(a,b) {
                return a.name<b.name
                }
                setState(jsonId, JSON.stringify(list.sort(sortName)), true);
                }
                
                on({id: persons, change: "ne"}, function(obj) {
                    checkOnline();
                });
                
                checkOnline();
                
                Codierknecht 1 Reply Last reply Reply Quote 0
                • Codierknecht
                  Codierknecht Developer Most Active @Snopy_16 last edited by

                  @snopy_16 sagte in Mehrere Objekte mit deren Datenpunkten in VIS Tabelle:

                  aber auch keine Sortierung

                  Versuch mal diese Sortierfunktionen:

                  function sortIP(a,b) {
                      if (a.ip < b.ip) {
                          return -1;
                      } else if (a.ip > b.ip) {
                          return 1;
                      } else {
                          return 0;
                      }
                  }
                  
                  function sortName(a,b) {
                      if (a.name < b.name) {
                          return -1;
                      } else if (a.name > b.name) {
                          return 1;
                      } else {
                          return 0;
                      }
                  }
                  

                  Dabei ist aber zu beachten, dass Groß- und Kleinschreibung beachtet wird.
                  Wenn das keine Rolle spielen soll, müsste das etwas umformuliert werden.

                  if (a.name.toLowerCase() < b.name.toLowerCase()) 
                  

                  Und bevor die Frage kommt: Die IP ist ein String und wird auch als solcher sortiert (und nicht Zahlenweise).

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    Snopy_16 @Codierknecht last edited by

                    @codierknecht
                    Super, das war es
                    DANKE

                    OliverIO 1 Reply Last reply Reply Quote 0
                    • OliverIO
                      OliverIO @Snopy_16 last edited by

                      @snopy_16

                      seltsam, hab das aus dem gedächtnis aufgeschrieben, ich dachte das funktioniert so.
                      aber tatsächlich.
                      Eine universelle Methode wäre auch noch so.

                      ["ccc","bbb","aaa].sort(new Intl.Collator("de").compare)
                      
                      S 1 Reply Last reply Reply Quote 0
                      • S
                        Snopy_16 @OliverIO last edited by

                        @oliverio
                        Ok, trotzdem auch danke. Freue mich über jede Hilfe

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        954
                        Online

                        31.9k
                        Users

                        80.1k
                        Topics

                        1.3m
                        Posts

                        7
                        38
                        1630
                        Loading More Posts
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes
                        Reply
                        • Reply as topic
                        Log in to reply
                        Community
                        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                        The ioBroker Community 2014-2023
                        logo