我刚刚遇到了这个奇怪的问题,其中下面的代码按预期返回数组中所有对象的 refno但是
let records = await Expense.find({}).exec(); // records is an array of objects [{},{}]
for (let obj of records) { // the obj has a refno property which i want to change
obj.refno = 0 // this works as expected by changing refno property to 0
}
console.log(records)
下面这段代码将属性值更改为字符串不起作用
for (let obj of records) {
obj.refno = "QM"+obj.refno
}
console.log(records) // IN this the refno. doesnt change
我的要求是将 refno 更改为字符串
//the object
{
_id: 5efed2c813b03d331e4dc052,
refno: 102,
project: 'EV Battery Pack',
invoiceno: 'dia',
description: 'black frame',
date: '2020-07-03',
}
所以将属性更改为其他数字有效,但不是字符串,我无法理解这是如何发生的,或者我错过了什么?无论如何我通过声明另一个属性并将字符串存储在其中解决了这个问题,但我不知道为什么 int 不能更改为对象内的字符串
有人可以解释为什么会发生这种情况
谢谢帮助
编辑:费用模式
var schema = new Schema({
refno: { type: Number, require: true },
project: { type: String, require: true },
projectid: { type: Number, require: true },
invoiceno: { type: String, require: true },
description: { type: String, require: true },
date: { type: String, require: true },
INR: { type: Number, require: true },
USD: { type: Number, require: true },
remarks: { type: String, require: true },
});
白衣非少年
相关分类