dev
dev

Reputation: 745

Accessing object in collection using helper with Meteorjs

So I created a helper

user(id = false, data = 'name') {
    if(parseInt(id) === id)
        return UserDetails.findOne({'id': id})[data]; // fetch one - details
    else
        return UserDetails.find({}).fetch(); // fetch all
}

problem comes from the fact that some of the elements in my collection are objects

user_avatar : {
    url: 'avatar.png',
    size: 14.4
} 

and I can't access those using {{ user UserID user_avatar.url }} is there a right way of doing this ?

Upvotes: 0

Views: 30

Answers (1)

dev
dev

Reputation: 745

Okay I figured it out

Instead:

return UserDetails.findOne({'id': id})[data];

I used the stevezhu:lodash package and

return lodash.get(UserDetails.findOne({'id': id}), data);

now with {{ user UserID 'user_avatar.url' }} I get the fine result.

Upvotes: 1

Related Questions