[英]How do I make sure null and empty string fields arent added to my documents in firestore Reactjs
I am adding objects to a document and I want to make sure empty strings and null instances don't add fields as I only want to create fields once they have been actually added我正在向文档中添加对象,并且我想确保空字符串和 null 实例不会添加字段,因为我只想在实际添加字段后创建字段
await updateDoc(itemRef,
{thing: '3232',
thing2: null,
thing3:'' });
}
how do I make sure only thing: 3232 is in the new document and the best way to go about it?我如何确定唯一的事情:3232是在新文件中和go有关的最好方法吗?
Probably easiest to just write a function that filters the property keys based on value:可能最简单的方法是编写一个基于值过滤属性键的 function:
function filterInPlace(obj) {
for (const [key, value] of Object.entries(obj))
if (obj[key] == null || obj[key] == '')
delete obj[key]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.