我无法让autoValue多次触发,即使文档建议它始终运行:
var saleItem = new SimpleSchema({
productId: {
label: 'Product Id',
type: String
},
sku: {
label: 'Item Name',
type: String
},
name: {
label: 'Item Name',
type: String
},
price: {
label: 'Item Price',
type: Number,
decimal: true,
min: 0
},
qty: {
label: 'Item Quantity',
type: Number,
min: 0
},
subtotal: {
label: 'Item Subtotal',
type: Number,
decimal: true,
autoValue: function(doc) {
console.log(doc);
return doc.$push.items.price * doc.$push.items.qty;
}
}
});
控制台在第一次插入文档时记录JSON文档,但之后不记录。重要的是要注意这个模式是一个子模式。