發生了什麼事情,當點擊.addGuest時,除了用餐變得未定義以及我的視圖被破壞之外,所有的工作都是有效的。 {{#if所有者}}顯示的所有內容都不會顯示,並且我的控制檯中出現此錯誤。流星collection.update導致會話變量被重置
Exception in template helper: TypeError: Cannot read property 'owner' of undefined
at Object.Template.menu_details.helpers.owner (http://localhost:3000/client/workflow/meal_details_page/meal_details.js
我的服務器控制檯上沒有錯誤,所有傳遞的數據都存儲在我的數據庫中。不知何故Session.get('current_meal')在invite方法上丟失了它的數據。我已經從事件處理器中評論了它,其他一切都很完美。
感謝
這是我的查詢迷路......
meal: function() {
return MealModel.findOne(Session.get('current_meal'));
},
owner: function() {
var meal = MealModel.findOne(Session.get('current_meal'));
return meal.owner === Meteor.userId();
},
,這裏是我的服務器
invite: function (options) {
check(options, {
mealId: String,
firstName: String,
lastName: String,
email: String
});
var meal = MealModel.findOne(options.mealId);
if (! meal || meal.owner !== this.userId)
throw new Meteor.Error(404, "No such meal");
MealModel.update(options.mealId, {$addToSet: {
invited: {
firstName: options.firstName,
lastName: options.lastName,
email: options.email
}}});
},
我Meteor.call功能...
方法invite = function(options) {
Meteor.call('invite', options);
},
最後,我的事件處理程序...
'click .addGuest': function (evt, tmpl) {
var firstName = tmpl.find('.firstName').value;
var lastName = tmpl.find('.lastName').value;
var email = tmpl.find('.email').value;
var meal = Session.get('current_meal');
if (firstName.length && lastName.length && email.length) {
var id = createGuest({
firstName: firstName,
lastName: lastName,
email: email,
meal: meal._id,
owner: meal.owner
});
invite({
firstName: firstName,
lastName: lastName,
email: email,
mealId: meal._id
});
};
return false;
},
搜索'Session.set('current_meal'',你用它在那裏 – 2014-09-03 23:00:55
你所看到的是一個基本的模板後,我的設置? Sessi關於什麼是帖子模板。 – 2014-09-03 23:17:14
我已經閱讀過文檔,我需要更新對象時的回調。我不明白該怎麼做。 – 2014-09-03 23:25:05