我想从mongodb属性设置会话。我在本地工作,但部署后,我在控制台中得到这个错误,并死亡的白色屏幕。流星Session.set()从mongodb财产助手功能不工作后部署
Exception from Deps recompute: TypeError: Cannot read property 'siteTheme' of undefined
// helper
Handlebars.registerHelper("site", function(){
host = headers.get('host');
theSite = Site.findOne({'domain': host});
theme = theSite.siteTheme;
// Problem - Works locally, not deployed with mup.
// Exception from Deps recompute: TypeError: Cannot read property 'siteTheme' of undefined
Session.set("theme", theme);
return theSite;
});
// Add theme class to html
siteTheme0 = function(){
$('html').addClass('theme0');
};
siteTheme1 = function(){
$('html').addClass('theme1');
};
siteTheme2 = function(){
$('html').addClass('theme2');
};
siteTheme3 = function(){
$('html').addClass('theme3');
};
// Change theme on change to db
Deps.autorun(function (c) {
if (Session.equals("theme", "1")){
siteTheme1();
}
else if (Session.equals("theme", "2")){
siteTheme2();
}
else if (Session.equals("theme", "3")){
siteTheme3();
}
else {
Session.set("theme", "0");
siteTheme0();
}
});
打开mongo控制台并确保其中有实际的数据。如果在''domain':host'没有数据,则不会返回任何数据,这会导致您的错误。为此,在你的项目目录中打开一个终端并输入'meteor mongo'来访问你的mongo shell。 – mjkaufer
不相关,但也许值得指出的是,你的句柄助手函数中的'host','site'和'theme'变量最终将成为全局变量。可能不太好。你应该用'var'作为前缀。 – Sean