gpt4 book ai didi

javascript - 通过忽略值来更新索引数据库中的对象

转载 作者:行者123 更新时间:2023-12-02 23:54:00 26 4
gpt4 key购买 nike

我写了下面的代码

updatePublication(projectName, publicationId, publicationObj, callback) {
let self = this;
this.initDatabase(function (db) {
let tx = self.db.transaction(self.PUBLICATIONS, self.READ_WRITE);
let store = tx.objectStore(self.PUBLICATIONS);
let index = store.index(self.PROJECT_NAME);

let request3 = index.openCursor(IDBKeyRange.only(projectName));
console.log("hrere");
request3.onsuccess = function () {
let cursor = request3.result;
if (cursor) {
let updateObject = cursor.value;
if (updateObject.publicationID == publicationId) {
updateObject.publicationObject = publicationObj;
cursor.update(updateObject);
callback(publicationId);
}
cursor.continue();
} else {
callback(publicationId);
}
};
});
}

但这给出了错误: enter image description here

我检查了错误原因。这是因为,传递的publicationObj有一个名为_requestObjectBuilder的对象,该对象的类型为Subscriber。

在代码中的某个地方使用如下:_requestObjectBuilder = 间隔(1000).pipe(tap(() => {}));

有什么方法可以修改我的 updatePublication 代码以忽略此值吗?索引数据库是否支持忽略值并保存数据的查询?

注意:如果我设置publicationObj._requestObjectBuilder = undefined,数据将保存到indexedDB。但这破坏了使用 _requestObjectBuilder 的功能。

最佳答案

通过克隆对象并将其设置为未定义来修复问题

let clonedObject = Object.assign({}, publicationObject);
clonedObject._requestObjectBuilder = undefined;

现在我正在更新克隆对象

关于javascript - 通过忽略值来更新索引数据库中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55488968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com