Sunday 15 January 2012

javascript - Meteor, how to access to a helper from another helper? -


मेरे पास एक सहायक है

  Template.user_profile.helpers ({उपयोगकर्ता: फ़ंक्शन ) {वापसी Meteor.users.find ({'profile.front_name': सत्र .get ('स्लग')})। Fetch () [0];}});   

मैं संग्रह करने के लिए एक सहायक जोड़ना चाहता हूं जो उपयोगकर्ता सहायक को एक्सेस कर सकता है और वर्तमान उपयोगकर्ता के साथ _id इसकी तुलना कर सकता है > _id , यह जानने के लिए कि उपयोगकर्ता अपनी प्रोफ़ाइल पर जा रहा है या नहीं। मैं कुछ बहुत बदसूरत का उपयोग कर रहा हूं:

  खाका कोड:  
  Template.user_profile.helpers ({उपयोगकर्ता: फ़ंक्शन () {वापसी Meteor.users.find ({'profile.front_name': सत्र .get ('userId')})। Fetch () [0];} , IsCurrentUser: function () {return Template.user_profile._tmpl_data.helpers.user () ._ id === Meteor.userId ();}});   

क्या कोई अन्य सहायक पहुंचने का कोई बेहतर तरीका है?

मैंने कंसोल में यह केवल गलती से खोज की है:

  Template.registerHelper फ़ंक्शन (नाम, फ़ंक्शन) {Blaze._globalHelpers [name] = func; }   

अतः, ब्लेज़._ ग्लोबल हॉलर्स है जो हम खोज रहे हैं!

No comments:

Post a Comment