A
A
assacasacsacsaca2018-03-05 18:13:35
css
assacasacsacsaca, 2018-03-05 18:13:35

How to update data on a page?

socket.on('ten', function(msg) {
                for (var i = 0; i < msg.data.length; i++) {
                    $("table").append("<tr><td>"+msg.data[i]+"</td></tr>");
                }
            });

<table id="log1"></table>

This function takes a structure like [0.0, 0.003202049311551491, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] and outputs the resulting data. But when the data comes in again, it does not replace the old ones, but outputs the new data again. How to make it remove old ones and add new ones?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pushkarev, 2018-03-05
@assacasacsacsaca

socket.on('ten', function(msg) {
    $("table").html('');

    msg.data.forEach(item => $("table").append(`<tr><td>${item}</td></tr>`));
});

Move away from jQuery to Vue, React...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question