【发布时间】:2020-08-04 00:32:27
【问题描述】:
我正在尝试使用ReactJS 为PouchDB 中的实体标签创建design。我设法使用put 函数保存了我的设计,但是当我查询我的设计时,响应只是一个空数组,我在控制台中收到以下错误:
TypeError: Cannot read property 'emit' of undefined
我认为问题出在我后来用作设计变量的映射参数的函数中:
function emitTagsMap(doc)
{
if (doc !== undefined)
{
if (Array.isArray(doc.tags))
{
doc.tags.forEach(x =>
{
/* Here is probably the problem - this.db is undefined */
this.db.emit(x, null);
});
}
}
};
this.db 在构造函数中声明:
constructor(service, name)
{
if (!service || !name) throw new Error("PouchDatabase initialized incorrectly");
this.name = name;
this.db = new PouchDB(name);
this.service = service;
this.tagsView();
}
请记住,我对PouchDB 完全陌生。
任何想法如何初始化emit 函数?
提前谢谢你。
【问题讨论】:
-
您能否发布您的 emitTagsMap 函数周围的代码。 this.db 在哪里声明?
-
我在代码中添加了构造函数,这就是声明this.db的地方
-
尝试以这种方式编写您的方法 emitTagsMap = (doc) => {....}