我知道这个问题是在最近才问的7岁之前提出的。我试图保存一个杂项,然后需要填充该杂项以填充createdBy
和assignedTo
字段,因为在对添加杂项功能的反应parentCallback()
中需要填充这些杂项。但是它在createChore猫鼬调用中遭到炸弹攻击。
Chore控制器:
exports.createChore = function(req, res) {
var newChore = new Chore(req.body);
newChore.save()
.populate('createdBy')
.populate('assignedTo')
.exec(function(err, chore) {
if(err)
return res.send(err)
res.json(chore);
});
};
添加杂项通话:
postChore(choreData).then(async (data) => parentCallback(data));
处理回调函数:
function handleCallback(data) {
const arr = [...chores];
let newChore = (
<Chore
key={data._id}
index={data._id}
dueDate={moment(data.dueDate).format("MM/DD/YY")}
title={data.title}
desc={data.desc}
time={data.time}
reaccurance={data.reaccurance}
reward={data.reward.toFixed(2)}
retryDeduction={data.retryDeduction}
status={data.status}
retryCount={data.retryCount}
rejectedReason={data.rejectedReason}
portal={props.portal}
assignedTo={data.assignedTo.firstName}
/>
);
arr.push(newChore);
setChores(arr);
setLoading(false);
}