如何獲取我在集合或方法中的失敗插入中引發的錯誤的值。如何在流星視圖模板中顯示錯誤
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