尝试使用Dexie.JS
:
function findEvent(key) {
let snippet = '';
if (!db.isOpen()) {
lastEvent = lastEvent.then(() => db.open());
}
lastEvent = lastEvent.then(() => db.transaction('r', db.events, () => {
db.events.each((element) => {
let d = element.cause.data;
if (d.hasOwnProperty('deleted') && (false == d.deleted) && d.hasOwnProperty('abbreviation') &&
d.hasOwnProperty('contents') && (d.abbreviation == key)) {
console.log(`found matching snippet for key: ${key}, contents: ${d.contents}`);
snippet = d.contents;
}
}).then(() => {
console.log('search callback returning:', snippet);
return snippet;
});
}));
return lastEvent;
}
我称之为:
return findEvent(request.key).then((result) => {
console.log(`findEvent return: ${result}`);
});
显然,我做错了什么。我的承诺以正确的顺序执行。我从snippet
内部的日志中正确打印findEvent
。在调用代码中记录result
时,它为undefined
。
应该采取哪些不同的方式?
答案 0 :(得分:1)
你不是{{1}来自chmod +r term_boot.exp
的承诺,所以未定义会被传达到你的顶级承诺中。