2015-04-17 37 views
1

There is a library that allows you to attach helpers to collections像這樣:應用幫手所有集合的MongoDB /流星

Meteor.users.helpers({ 
    profile: function() { 
    return Profiles.findOne(this.profileId); 
    } 
}); 

這個偉大的工程爲建立集合,但我想打,默認情況下適用於以往單個集合在我的數據庫「一般」的幫手。

EveryCollection.helpers({ 
    fullName: function() { 
    var schema = this.simpleSchema()._schema; 
    if(hasKey(schema, 'firstName') && hasKey(schema, 'lastName')) { 
     return getKey(this, 'firstName') + " " + getKey(this, 'lastName'); 
    } 
    } 
}); 

這樣一來,我可以這樣做:

> Admins.findOne().fullName(); 
"Cat Woman" 
> Meteor.users.findOne().fullName(); 
"Bat Man" 

這將是,默認情況下,添加到每個集合作爲一個幫手。這可能嗎?我想它需要添加一些東西到prototype,但無法找到合適的項目添加到。

編輯:比如說較差,想要的東西,在一個實例變量

回答