0

我已经扩展了一个Parse.Object. 现在我想在保存对象之前取消设置嵌套属性。此嵌套属性settings是一个对象。

所以我的钩子看起来像这样:

Parse.Cloud.beforeSave('MyObject', req => {
   if (req.object.get('settings').propertyToUnset) {
       req.object.unset('settings.propertyToUnset');
   }
});

但是,这会产生错误Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

嵌套属性如何unset工作?

4

2 回答 2

0

你可以尝试这样的事情:

Parse.Cloud.beforeSave('MyObject', async req => {
   const settings = req.object.get('settings');
   await settings.fetch();
   if (settings.get('propertyToUnset')) {
       settings.unset('propertyToUnset');
       await settings.save();
   }
});
于 2019-12-26T06:51:57.520 回答
0

解决方案是使用纯 JavaScript 命令delete删除嵌套对象的属性settings

Parse.Cloud.beforeSave('MyObject', req => {
    if (req.object.get('settings').propertyToUnset) {
        delete req.object.get('settings').propertyToUnset;
    }
});
于 2020-01-05T07:21:24.810 回答