javascript - Different values from different arrays and append together beside one another in a table -
so, trying pull out 2 different array values arrays chanarrid & chanarrname via express(socket.io) & node.js.
then once have display them in table on same row e:g
<tr class="exe"> <td>sip/487-00000060</td> <td>0000000001</td> </tr> <tr class="exe"> <td>sip/488-00000060</td> <td>0000000002</td> </tr>
then next set take new row, same following channel values.
when add pull next 2 out without repeating itself. have had kind of success fall short, wrong positioning or duplicated values.
i have working fine 1 value not both so:
call extension 488: add channel name , value page array etc.
works first 1 works fine seen @ top works grand following when add second pair of values:
<tr class="exe" id="exe"> <td>sip/487-00000060</td> <td>1445964898.228</td> <td>1445964898.2281445964900.229</td> </tr>
it skips sip name , adds 2 channel ids in next row.
below latest code have been tweaking, see ave been trying accomplish.
client side
socket.on('sipname', function (data,datad) { var sipname = ''; var sipid = ''; $(".exe").remove(); (i = 0; < data.length; i++) { sipname += data[i]; if (sipname) { $sipname.append('<tr class="exe" id="exe">\ <td id="siptd">' + sipname + '</td>'); } (i = 0; < datad.length; i++) { sipid += datad[i]; if (sipid) { $('#siptable td:last').after('<td>' + sipid + '</td></tr>'); } } sipid = ''; } });
server side function
function updatesip() { io.sockets.emit('sipname', chanarrname,chanarrid); chandump(); }
stasis: pushing values array
bridge.addchannel({ channel : channel.id }, function (err) { var name = chanarrname.push(channel.name) var id = chanarrid.push(channel.id) updatesip(); if (err) { throw err; }
hope guys can give me little bit of guidance.
in client code have nested for-loop same index variable outer loop, means outer 1 not run many times expected.
also, +=
operator concatenate new values previous values, explaining concatenated channel ids notice. expanding dom nodes incrementally, there no need use +=
. assign. same holds outer loop: assign sipname
=
.
indenting code correctly may debugging it.
finally, declare index variable(s) var
.
with these corrections, this:
socket.on('sipname', function (data, datad) { var sipname, sipid, datahtml; $(".exe").remove(); (var = 0; < data.length; i++) { sipname = data[i]; if (sipname) { datahtml = '<td id="siptd">' + sipname + '</td>'; (var j = 0; j < datad.length; j++) { sipid = datad[j]; if (sipid) { datahtml += '<td>' + sipid + '</td>'; } } $sipname.append('<tr class="exe" id="exe">' + datahtml + '</tr>'); } } });
edit:
above code updated after comments. version concatenates html each td
in variable, wrap in tr
tag , append $sipname
. have no view on variable $sipname
, assume set correctly.
there 1 thing need fix:
the code sets values id
properties of generated nodes, same ones. not acceptable in html: id should unique in document.
Comments
Post a Comment