@jmeister79 sagte in [Gelöst]Array darstellen in vis:
@stimezo
Voila!
var myarray = new Array(100);
var logbooktemp;
createState("javascript.0.logbook",'nixx',{type: 'string', name: 'Logbuchobjekt'});
createState("javascript.0.array_log", JSON.stringify(myarray), {type: 'string',name: 'Logbuchtabelle'});
on({id: 'javascript.0.LogText', change: "ne"}, function (obj) {
if (getState("javascript.0.LogText").val != 'leer') {
// Daten in temp Array holen
myarray = JSON.parse(getState('javascript.0.array_log').val);
//element vorne anfügen
myarray.unshift(formatDate(new Date(), "YYYY.MM.DD")+'-'+formatDate(new Date(), "hh:mm:ss")+' - '+getState("javascript.0.LogText").val);
//letztes element löschen
myarray.pop();
//in temp variable schreiben um zu übergeben
logbooktemp = '';
for (var n = 99; n >=0; n--){
logbooktemp = n+" - "+myarray[n]+'<br>'+logbooktemp;
}
//json objekt zurückschreiben
setState('javascript.0.array_log', JSON.stringify(myarray));
//auslösendes objekt zurücksetzen
setState("javascript.0.LogText"/*LogText*/, 'leer');
//ausgabeobjekt zurückschreiben
setState("javascript.0.logbook"/*LogText*/,logbooktemp);
}
});
Das hast Du aber gut gemacht ;-)
Viele Grüße
Christian