I have a table on my index.ejs
file that should display the current logged in users (via appending table rows). Here is how it's built:
<table id="status-table" class="table table-bordered table-hover">
<thead>
<tr>
<th>Player</th>
<th>Status</th>
<th>Score</th>
</tr>
</thead>
<tbody></tbody>
</table>
In my user.js
model (file route: assets/js/user.js), I create this function:
addUser: function(user) {
var found = false;
// Check if the user is already in the table
$('#status-table tr').each(function() {
var hasUser = $(this).attr('id');
if (hasUser !== undefined && ('user-' + user.id == hasUser)) {
found = true;
}
});
if (!found) {
var $table = $('#status-table');
var ready = (user.id == me.id) ? '<button type="button" id="changeStatus" class="btn btn-default btn-xs">change</button>' : '';
var row = '<tr id="user-'+user.id+'"><td class="name" data-avatar="'+user.avatar+'">'+user.name+'</td><td><img class="flag" src="http://api.hostip.info/flag.php?ip='+user.ip+'" width="20" height="14" alt=""><span class="status" data-status="'+user.status+'">'+user.status+'</span>'+ready+'</td><td class="score">'+user.score+'</td></tr>';
$table.append(row);
QW_MODULES.chat.updateUI();
}
}
This function should fire because in my app.js
I call an init to that entire user.js
file on "socket connection".
io.socket.on('connect', function socketConnected() {
QW_MODULES.user.init();
});
What could be going wrong to not fire this function? I'm not receiving any errors on login/sign up.
via ether
No comments:
Post a Comment