Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou a ter um problema que preciso de resolver com alguma urgência...
Eu tenho este código:
Connexy.bind('pusher:member_added', function(data){
// Check if the user left but then rejoined, this is mainly because of page browsing.
//
var pendingRemoveTimeout = $.Connexy.Storage.pendingRemoves[ data.info.session_id ];
if(pendingRemoveTimeout){
clearTimeout(pendingRemoveTimeout);
}
// If a user gets online.
//
if(data.info.type == 'user'){
// Check if the user is on the storage array.
//
if($.inArray(data.info.session_id, $.Connexy.Storage.users_online) == -1){
// Add the user to the storage array.
//
$.Connexy.Storage.users_online[ data.info.session_id ] = data.info;
// Show the notification.
//
Notifications.show("", "Visitor Online", "You have a new visitor online!");
// Add the user to the list.
//
$('#traffic-monitor #visitors .inner ul').append(
$('<li>').attr('id', data.info.session_id).append(
$('<span>').attr('class', 'tab').append("Teste de utilizador online")
)
);
}
}
// If an agents gets online.
//
else {
// Check if the agent is on the storage array.
//
if($.inArray(data.info.session_id, $.Connexy.Storage.agents_online) == -1){
// Add the agent to the storage array.
//
$.Connexy.Storage.agents_online[ data.info.session_id ] = data.info;
// Show the notification.
//
Notifications.show("", "Agent Online", "Bruno Gaspar is now online!");
// Add the agent to the list.
//
}
}
});
O problema está quando ele verifica se o valor já existe no array, eu estou a usar json array ( penso que seja assim que lhe chamam ) ou seja:
$.Connexy.Storage.users_online = {}
E sempre que algum utilizador é adicionado ele tem de verificar se já está no array, e se não estiver vou adicionar o mesmo ao array, usando:
$.Connexy.Storage.users_online[ data.info.session_id ] = data.info;
Eu sei que não posso usar o $.inArray , qual a forma para verificar se o valor já existe no "json array" ? E estou a adicionar correctamente ao array ?
Obrigado!
Consegui resolver:
if(!$.Connexy.Storage.users_online.hasOwnProperty(data.info.session_id))
Mas se houver outra maneira podem dizer =)
Carregando comentários...