Monday, 15 March 2010

node.js - Is there a way to say collection[attr1=value].attr2=value in Javascript? -


Is there a way to say something like this

  User.friends [id = 1] Javascript in .posts = data   

, where the user. Friends are a collection of friends, one of them has the 'id'?

I am a collection user. Friend, who is a collection of friend items that has 3 attributes (ID, Post and Choice). Internal Iterator instance variable, friend, pass-by-value not by reference; So, how do I set the properties of the parent object beautifully from inside an eaterator?

  async.each (user friend, function (friend, cb) {var url = "https: // graph .facebook.com/" + friend.id.id + "/? Fields = Post and = "+ moment (postFromDate) .format ('YYYY-MM-DD') + and access_token = '+ User.accessToken; Request.get ({url: url, json: true}, function (error , Feedback, body) {if (error and response.statusCode == 200} {console.log (body); // I want to set actual user.friend [i] .posts value, // But how can I not get the value of 'i'? Friend.posts = body.data; // This is just local friend var cb (null);} and {console.log (error); Tickets throw;}}); //...request.get}, function (error, results) {callback ();}); //...async_each   

Sorry if this is a dumb question. Any help really appreciated I have tried:

  _ Find (where user friend, {id: friend.id}). Posts = body.data;   

but it does not look like (I think it just sets a local value).

You can use the filter method: < Pre> var results = User.friends.filter (function (item) {return item} ID === 1;}) [0] .posts = data;

No comments:

Post a Comment