使用 Meteorjs 的助手访问 collection 中的 object

Accessing object in collection using helper with Meteorjs

所以我创建了一个助手

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
}

问题是因为我的 collection 中的某些元素是 objects

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

我无法访问那些使用 {{ user UserID user_avatar.url }} 的人,有正确的方法吗?

好的,我明白了

改为:

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

我使用了 stevezhu:lodash 包和

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

现在 {{ user UserID 'user_avatar.url' }} 我得到了很好的结果。