jquery Arrays, how to use each
I current have the following which works well:
channel.bind('pusher:subscription_succeeded', function(members) {
members.each(set_status_online);
})
function set_status_online(member) {
var user_temp;
user_temp = findWallUser(member.info.uid);
if (user_temp) {
user_temp.status('online');
}
else {
console.开发者_Python百科log('user not found');
}
}
I am trying to update the first part to give me more control of the members.each. I want something like this:
channel.bind('pusher:subscription_succeeded', function(members) {
members.each {
set_status('online');
}
})
Is there a way I can do that with the array & .each? thanks
With arrays, use $.each
like this:
$.each(members,set_status_online);
Change your function to have the index
as the first variable:
function set_status_online(index,member) {
etc...
}
Or if you don't want to modify your function, you can do this with the $.each
:
$.each(members,function(i,e){
set_status_online(e)
});
channel.bind('pusher:subscription_succeeded', function(members) {
members.each(function(member) {
set_status('online', member);
});
})
function set_status(setStatusToWhat, member) { //setStatusToWhat would be 'online'
;
}
精彩评论