我在應用程序的側邊欄中收到以下錯誤消息。流星:模板幫助程序中的例外不會消失
Exception in template helper: TypeError: Cannot read property 'org' of undefined at Object.Template.sidebar.helpers.orgUsers (http://localhost:3000/client/templates/includes/sidebar.js?85f4645305c91378ab2c0648488f2250753e8c70:3:29) at bindDataContext (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2786:16) at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1607:16) at http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2834:66 at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:3382:12) at wrapHelper (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2833:27) at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18) at http://localhost:3000/client/templates/includes/template.sidebar.js?85456dfc1ce0f189b2d312b2422db8a2e35f337e:15:22 at null. (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2583:27) at http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1821:18
側欄應顯示特定於組織(用戶化)的用戶列表。助手向用戶發送如下:
Template.sidebar.helpers({
orgUsers : function() {
var org_id = Meteor.user().org._id;
var users = Meteor.users.find({
"org._id" : org_id
});
return users;
}
});
我在這裏發佈的user.org:
Meteor.publish("userData", function() {
if (this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'org._id': 1, 'org.active' : 1, 'emails.[0].address': 1, 'profile.name': 1, 'createdAt':1}});
} else {
this.ready();
}
});
目前我出版這與鐵路由器每一頁。它看起來是助手多次運行,並且第一次幾次它沒有org_id也沒有org._id,但它最終得到它並顯示。雖然每次刷新頁面都會出現這個令人討厭的控制檯錯誤。任何幫助深表感謝。
路由器:
Router.configure({
layoutTemplate : 'layout',
loadingTemplate : 'loading',
notFoundTemplate : 'notFound',
waitOn : function() {
return [
Meteor.subscribe('orgUsers'),
Meteor.subscribe('appointments'),
Meteor.subscribe('allServicesData'),
Meteor.subscribe('allOrgsData'),
Meteor.subscribe('userData'),
];
}
});
謝謝!所以訂閱已經等待了。我要編輯問題以顯示路由器。我也嘗試了防守助手代碼,但仍然存在。 – Chris
您正在執行'Meteor.user()。org._id'並獲取'Can not read property'org'undefined',這意味着'Meteor.user()'在代碼運行時不存在。如果你剛剛檢查過,它應該! –