我想省略req.body的数据,收集在更新资源时,只有那些字段null或''集合中的现有资源。但这也可能是通用的,这就是标题更通用的原因。无论如何,请想象以下情况:我们的数据库中有一个用户具有以下数据:{ "firstName": "John", "lastName": "Doe", "address": { "Address1": "Random street 1", "City": "", "Country": null }, "email": ""}用户正在尝试使用以下数据更新现有资源:{ "firstName": "Mark", "address": { "Address1": "Random street 2", "City": "NY", "Country": "USA" }, "email": "john.doe@mail.com"}更新后的对象应该是这样的:{ "firstName": "John", // Unchanged because propety value already exists "lastName": "Doe", "address": { "Address1": "Random street 1", // Unchanged because propety value already exists "City": "NY", // Updated because existing value is empty ("") "Country": "USA" // Updated because existing value is null }, "email": "john.doe@mail.com" // Updated because existing value is empty ("")}我正在使用猫鼬,但我宁愿在基本的 javascript 对象级别上实现它
添加回答
举报
0/150
提交
取消