如何获取我在集合或方法中的失败插入中引发的错误的值。如何在流星视图模板中显示错误
Customers.allow({
insert: function(userID, rec) {
console.log(userID === rec.userID);
if (rec.userID === null) {
throw new Meteor.Error(600, "You must be logged in");
};
if (rec.phone.length != 10) {
throw new Meteor.Error(601, "Incorect phone format", "Phone must be 10 chars long");
};
if (rec.fax.length != 10) {
throw new Meteor.Error(602, "Incorect fax format", "Fax must be 10 chars long");
};
return userID === rec.userID;
}
});
所以现在我看到控制台上的错误,但是说如果想要显示模板中的错误或将其存储在反应会话中,以便它可以显示给用户进行更正。
像尝试到这样的事情。
Template.form.errors = function() {
// return however you get to those thrown errors
}
你有没有管理,使这项工作? Tarang提供的解决方案不适用于我。谢谢。 – Ben 2013-11-17 02:58:22
ok对我而言,现在我在Tarang的答案中添加了一条评论,它使它适用于我 – Ben 2013-11-17 21:02:30