1
我有一個函數,從數據庫中獲取一些數據,並將其綁定到某個變量:不能在貓鼬函數添加屬性的對象
exports.getAccDoc = function(req, res, send, next) {
var AccDoc = require('../models/accdoc');
AccDoc.find({
startup_id: req.startup.startup_id
}).exec().then(function(accDocs) {
vm.accDocs = accDocs; //I'm using vm in my view
console.log(vm.accDocs); //logs a array that contains one object
console.log(vm.accDocs[0]); //you know
vm.accDocs[0].test = 'TEST'; //trying to add some property to the object
console.log(vm.accDocs[0].test); //logs TEST like it should be
console.log(vm.accDocs[0]); //logs an object, But it doesn't contain test property
send(res); //sending vm to view
});
};
爲什麼我的對象不加test
屬性之後的變化?
(我雖然可以更改屬性的現有值,但不能添加新屬性)
顯然你不能。看到這個:http://stackoverflow.com/questions/18554350/unable-to-add-properties-to-js-object – PeterVC
@PeterVC這很難搜索我認爲。謝謝。 –