rows 是数组,row 是对象,我想给 row 添加一个属性;我尝试了以下方法:
rows.forEach(function(row) {
User.find(row.owner).success(function(user) {
row.ownername = user.username;
});
});
console.dir(rows);
但是行没有加入 ownername 属性,输出仍然是 [],我错过了什么吗?任何帮助表示赞赏。
不好意思,我说的不清楚,rows是数组,比如:
[{"id":19427,"name":"data1","owner":123},
{"id":19427,"name":"data2","owner":123},
{"id":19427,"name":"data3","owner":123},
{"id":19427,"name":"data4","owner":123}]
row 表示行的一个元素,例如
{"id":19427,"name":"data2","owner":123}
我只想在行中添加一个属性,最后是行
[{"id":19427,"name":"data1","owner":123,"ownername":"a"},
{"id":19427,"name":"data2","owner":123,"ownername":"ab"},
{"id":19427,"name":"data3","owner":123,"ownername":"abc"},
{"id":19427,"name":"data4","owner":123,"ownername":"abcd"}]