मेरे अधिकांश टेम्पलेट हेल्पर्स में परिणाम धूमिल होते हैंत्रुटियों और मुझे यकीन नहीं है कि क्यों। उन्हें और अधिक अजीब बनाता है कि वे प्रतिपादन या घटनाओं को बिल्कुल भी टेम्पलेट्स से ब्लॉक नहीं करते हैं, वास्तव में, ऐप ठीक काम करता है।
मुख्य मुद्दा गन्दा, गन्दा, सांत्वना है। इसका एक उदाहरण नीचे दिया गया है:
Template.templatename.helpers({
adminhelper: function(){
var theUser = Meteor.user(),
theUserId = theUser["_id"];
if(theUserId == "XXX"){
return true;
}
}
});
जाँच का सिर्फ एक तरीका है कि कौन सा उपयोगकर्ता एक व्यवस्थापक उपयोगकर्ता है। इसका परिणाम यह होगा:
Exception in template helper: TypeError: Cannot read property "_id" of undefined
at Object.Template.templatename.helpers.adminhelper (http://localhost:3000/client/lib/helpers.js?37db222f849959237e4f36abdd8eba8f4157bd32:5:23)
at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2693:16
at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1602:16
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?3c496d2950151d744a8574297b46d2763a123bdf:169:18)
at Template.manage.Blaze.If.HTML.HEADER.HTML.DIV.class (http://localhost:3000/client/views/template.templatename.js?868248757c652b031f64adad0edec9e2a276b925:6:22)
at null.<anonymous> (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2454:44)
at http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1795:16
at Object.Blaze._withCurrentView (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:2029:12)
at viewAutorun (http://localhost:3000/packages/blaze.js?77c0809654ee3a10dcd5a4f961fb1437e7957d33:1794:18)
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
दिलचस्प है, ग्राहक / विचार / टेम्पलेट .emplatename.js मौजूद नहीं है। मैंने सभी हेल्पर्स को एक हेल्पर्स.जेएस फाइल में और एक ईवेंट्स.जेएस फाइल में सभी इवेंट्स डाल दिए।
मेरे मार्ग के लिए मेरे पास है
Router.route("/theurl",function(){
this.render("templatename");
},{
waitOn: function(){
return Meteor.user();
}
});
मैं भविष्य में इन मुद्दों से बचने के लिए क्या कर सकता हूं?
उत्तर:
जवाब के लिए 2 № 1बस एक का उपयोग करें रक्षक के अस्तित्व के लिए जाँच करने के लिए Meteor.user()
निकालने से पहले _id
। की प्रतीक्षा कर रहे Meteor.user()
मार्ग में t "काम नहीं करता है, जैसा कि waitOn
एक सदस्यता की आवश्यकता है। वैकल्पिक रूप से आप ऐसा कर सकते हैं:
Template.templatename.helpers({
adminhelper: function() {
return Meteor.userId() === "XXX";
}
});
एक और भी बेहतर समाधान का उपयोग करने के लिए है भूमिकाओं पैकेज.