angular - Firestore 使用 Angular Map 对象设置文档
问题描述
我想为我的 firstore 设置一个文档。该文档如下所示:
export interface ICountry {
key: string;
translations: Map<string,string>;
}
例如,国家“法国”将作为翻译
translations.get('fr') === 'France'; // French
translations.get('nl') === 'Frankrijk'; // Dutch
translations.get('de') === 'Frankreich'; // German
但如果我现在想将该文件上传到我的 Firestore,
public async setCountry(country: ICountry): Promise<void> {
return this.firestore
.collection(this.collectionPath)
.doc(country.key).set(country);
}
然后我收到以下错误
错误:未捕获(承诺中):FirebaseError:[code=invalid-argument]:使用无效数据调用的函数 DocumentReference.set()。不支持的字段值:自定义 Map 对象(在文档国家/法国的字段翻译中找到)
Firestore 似乎无法保存这种Map
格式。所以我现在想知道
- 是否有更好的数据结构来保存我的翻译?
- 如果没有,我需要将我的转换
Map<string,string>
为什么以及如何保存它。
解决方案
推荐阅读
- java - 提供来自 J2EE 的静态非编译文件
- parsing - Scrapy - 解析对齐问题
- amazon-web-services - 100-200 upserts 并在 10 秒的窗口中插入 3 节点 redshift 集群是一种现实的架构吗?
- python - 如何从语言价格中删除 \r\n?
- python - 如何使用一种或多种不同类型的标签来标记对象,以便以后对其进行排序?
- mysql - 没有子查询,为只有空帖子的作者选择所有 author_id
- angularjs - ng-if,有没有办法在循环遍历数组时停止对数组的最后一个元素应用条件?
- c# - 如何使用 C# Selenium 在移动模拟器横向模式下启动 Chrome?
- android - 如何制作一个可以连接警报系统(本地网络)并从其读取数据的 Android 应用程序?
- c# - 如果 DataGridView 单元格中的值为 NaN,如何防止崩溃,或者限制用户直到单元格中有值?