Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. Jahreszahl in der Objekt ID Automatisch ersetzen

    NEWS

    • Neues Video "KI im Smart Home" - ioBroker plus n8n

    • Neues Video über Aliase, virtuelle Geräte und Kategorien

    • Wir empfehlen: Node.js 22.x

    Jahreszahl in der Objekt ID Automatisch ersetzen

    This topic has been deleted. Only users with topic management privileges can see it.
    • Jey Cee
      Jey Cee Developer last edited by

      Ich wurde gefragt ob es möglich ist die Jahreszahl in einer Objekt ID mit einem Binding zu ersetzen. Soweit ich weis geht das nicht, deswegen hab ich ein Skript angepasst um das Problem zu lösen.
      Für den fall das noch jemand anderes es brauchen kann Veröffentliche ich hier die Lösung.

      Im Widget unter Generell bei CSS Klassse gibt man year ein.

      Bei der Objekt ID ersetzt man die Jahreszahl durch <year>.

      0_userdata.0.<year>
      

      Skript (VIS Editor):

      const timeout = 50;
      
      $(document).ready(function(){
          setTimeout( () => {
              replaceYear();
          }, timeout)
      
      });
      
      
      function replaceYear(){
      
      let year = new Date().getFullYear();
      
      const yearElements = document.querySelectorAll('div[class*="year"]');
      
      for (let i = 0; i <= yearElements.length - 1; i++) {
              const arr = [ ...yearElements[i].classList ];
              const propName = arr.find(checkForYear).replace('year', '');
              const id = yearElements[i].lastElementChild.lastElementChild.dataset.oid.replace('<year>', year);
      
              console.log(id);
      
                vis.conn.getStates(id, (err, state) => {
                    if (!err){
                        yearElements[i].lastElementChild.lastElementChild.outerText = state[id].val;
                    }
      
                  })
          }
      
      }
      
      function checkForYear(className) {
          const regex = new RegExp('year');
          let finding = className.match(regex);
      
          return finding;
      }
      
      1 Reply Last reply Reply Quote 2
      • First post
        Last post

      Support us

      ioBroker
      Community Adapters
      Donate

      974
      Online

      32.1k
      Users

      80.7k
      Topics

      1.3m
      Posts

      vis
      1
      1
      157
      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