1
我在流星(我使用模式)中有以下方法,我为了在数据库中插入一个对象而调用它。通过模板传递方法参数
userAddOrder: function(newOrder, prize) {
var currentPrize;
if (prize == undefined) {
currentPrize = undefined;
}
else{
currentPrize = prize;
}
// Ininitalize the newOrder fields.
// Check if someone is logged in
if(this.userId) {
newOrder.userId = this.userId;
// Set the weight and price to be processed by the admin in the future
newOrder.weight = undefined;
newOrder.price = currentPrize;
newOrder.status = false;
newOrder.receiveDate = new Date();
newOrder.deliveryDate = new Date();
Orders.insert(newOrder);
} else {
return;
}
},
一般来说,我必须通过它作为参数的“奖品”参数。问题是,尽管配置了奖品,但我无法通过模板找到将其传递给方法的方法。我想一个办法是让一个助手,并尝试通过它:
{{#autoForm schema="UserOrderSchema" id="userInsertOrderForm" type="method" meteormethod="userAddOrder,prizeRequest"}}
但它返回一个错误:
"method not found"
另一种方法是使用一个简单的调用在js文件的方法形式(不是提供的autoform)。我认为第二个应该可以工作,但我不想重写整个模板。有没有办法做到这一点?
谢谢你的答案。其实,我找到了另一种方式。我刚刚添加了一个隐藏字段,其值是提到的帮助者:{{> afQuickField name ='price'value = prizeRequest type =“hidden”}} – StefanL19
确实,这很简单:) – tarmes