Reputation: 3402
I have a jQuery code:
$('#users').append(users.join('')).filter(function(i) {
return ids.indexOf(this.id) === -1;
}).remove();
How can I rewrite this code using Mootools javascript library? Thanks.
Full code below:
...
success: function(r) {
var users = [],
ids = [];
for(var i=0; i< r.users.length;i++){
if(r.users[i]){
users.push(_chat.render('user', r.users[i]));
ids.push('user-' + r.users[i].name);
}
}
$('#users').removeClass('sending2').append(users.join('')).children().filter(function(i) {
return ids.indexOf(this.id) === -1;
}).remove();
}...
Upvotes: 1
Views: 182
Reputation: 26165
Not sure what users will contain - assuming elements with an id like user-name
var users = ["<div id='user-john'>john</div>", "<div id='user-bob'>bob</div>"],
ids = ['user-john'];
$("users").adopt(new Element('div', {html: users.join('')}).getChildren().filter(function(user){
return ids.indexOf(user.get('id')) !== -1; // unless it's another this.id...
}));
Not sure it's the same but should get you started. it only injects the filtered ones. if you want the opposite, reverse the filter to === -1; - it's using a dummy div element to host the dynamic ones from the array and filter them outside the dom, rather than inside, which will be slower.
Upvotes: 2