NEWS
Zeile aus JSON löschen
-
Hallo ich erstelle eine JSON Tabelle
const idkommt = '0_userdata.0.Haus.AW.Noel_kommt'; const idgeht = '0_userdata.0.Haus.AW.Noel_geht'; const idJSON = '0_userdata.0.Haus.AW.Noel_JSON'; const idTable = '0_userdata.0.Haus.AW.Noel_JSON'; // ID JSON-Tabelle const ids = ['0_userdata.0.Haus.AW.Noel_kommt','0_userdata.0.Haus.AW.Noel_geht']; var table = []; for(let i = 0; i < ids.length; i++) { table[i] = {}; table[i].Name = getObject(ids[i]).common.name; table[i].Wert = getState(ids[i]).val; } setState(idTable, JSON.stringify(table), true); on(ids, function(dp) { let idx = ids.indexOf(dp.id); table[idx].Wert = dp.state.val; setState(idTable, JSON.stringify(table), true); });
Wie kann ich nach einer bestimmten Zeit etwa bei Tageswechsel die erste Zeile löschen?
Gruß
Michael -
@michihorn sagte: bei Tageswechsel die erste Zeile löschen?
const idTable = '0_userdata.0.Haus.AW.Noel_JSON'; // ID JSON-Tabelle schedule('59 23 * * *', function() { const arr = JSON.parse(getState(idTable).val); arr.shift(); setState(idTable, JSON.stringify(arr), true); }); -
@paul53 Danke Dir das klappt, kann ich auch löschen nach "_geht" oder "_kommt"?
-
@michihorn sagte: auch löschen nach "_geht" oder "_kommt"?
Den ersten Eintrag?
const idTable = '0_userdata.0.Haus.AW.Noel_JSON'; // ID JSON-Tabelle schedule('59 23 * * *', function() { const arr = JSON.parse(getState(idTable).val); if(arr[0].includes('_geht')) { arr.shift(); setState(idTable, JSON.stringify(arr), true); } });