我是 javascript 新手,我对以下代码有疑问。我正在尝试从回调中设置价格值,但不起作用......请帮忙?
PreInvoiceSchema.pre('save', function(next) {
//Seperating code from state
var codestate = addr[2].split(/[ ,]+/);
this.customer.zipcode = codestate[2];
this.customer.state = codestate[1];
//Calculating base price
if (this.order_subtype == "Upgrade") {
this.price = 30;
} else {
this.price = 50;
}
var self = this;
for (var j = 0; j < this.work.length; j++) {
Price.findOne({
"item": self.work[j].workproduct
}, function(err, val) {
if (self.work[j] != undefined) {
self.work[j].workprice = 300; <-- this doesn't work
}
});
});