簡體   English   中英

流星:模板助手中的異常不會消失

[英]Meteor: Exception in Template Helper not going away

我從應用程序的側邊欄收到以下錯誤。

模板助手中的異常:TypeError:無法讀取Object.Template.sidebar.helpers.orgUsers上未定義的屬性“ org”( http:// localhost:3000 / client / templates / includes / sidebar.js?85f4645305c91378ab2c0648488f2250753e8c70:3:29 )在bindDataContext( HTTP://本地主機:3000 /包/ blaze.js 4e49999979a58da0e2265f7bd3f5910f9901b07b:2786:16 )在Blaze._wrapCatchingExceptions( HTTP://本地主機:3000 /包/ blaze.js 4e49999979a58da0e2265f7bd3f5910f9901b07b:1607:16 )在HTTP :// localhost:3000 / packages / blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2834:66 at Function.Template._withTemplateInstanceFunc( http:// localhost:3000 / packages / blaze.js? 4e49999979a58da0e2265f7bd3f5910fwr1b12er() : //localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2833:27 )在Object.Spacebars.call( HTTP://本地主機:3000 /包/ spacebars.js 7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18 )中的HTTP://本地主機:3000 / client / templates / includes / template.sidebar。 js?85456dfc1ce0f189b2d312b2422db8a2e35f337e:15:22為空。 http:// localhost:3000 / packages / blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2583:27 )在http:// localhost:3000 / packages / blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1821:18

邊欄應顯示特定於組織(anization)的用戶列表。 發送用戶的助手如下:

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();
    }   
});

目前,我正在使用Iron Router將其發布到每個頁面。 看來該幫助程序已運行了好幾次,並且在最初的幾次它沒有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'), 

    ];
}

});

用戶對象可用之前,您的助手正在運行。 您可以讓iron-router waitOn訂閱userData (建議的方法),也可以防御性地編碼您的助手:

Template.sidebar.helpers({
  orgUsers : function() {
    if ( Meteor.user() ){
      var org_id = Meteor.user().org._id;

      var users = Meteor.users.find({
        "org._id" : org_id
      });
      return users;
    }
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM