javascript - 通过忽略值更新索引数据库中的对象
问题描述
我写了下面的代码
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);
}
};
});
}
我检查了错误的原因。这是因为,传递的publicationObj 有一个名为_requestObjectBuilder 的对象,它属于订阅者类型。
在代码中的某处使用如下: _requestObjectBuilder = interval(1000).pipe(tap(() => {}));
有什么办法可以修改我的 updatePublication 代码以忽略此值?索引数据库是否支持忽略值并保存数据的查询?
注意:如果我设置publicationObj._requestObjectBuilder = undefined,数据将保存到indexedDB。但这破坏了使用 _requestObjectBuilder 的功能。
解决方案
通过克隆对象并将其设置为未定义修复了该问题
let clonedObject = Object.assign({}, publicationObject);
clonedObject._requestObjectBuilder = undefined;
现在我正在更新 clonedObject
推荐阅读
- javascript - 如何在Angular的同一页面上使用多个ngx-slick-carousel?
- python-3.x - 如何在for循环中动态模拟python函数的结果?
- sql - 使用聚集索引的内部连接约束(需要空值)
- spring-kafka - 多个消费者使用 spring kafka 并在 spring 之外编写回复主题
- azure - DataFactory 将字符串(年份为 2 位)转换为日期
- .net - 未能将路线匹配到正确的操作
- reactjs - 发布带有反应应用程序到 IIS 的 .net core 3.1
- css - 与 figma 相比,字体提供不同的输出
- pip - Jupyter Notebook - ImportError: lxml not found, please install it
- amazon-web-services - 执行查询时 Athena 权限被拒绝