【发布时间】:2020-09-17 17:19:12
【问题描述】:
我有一个缺少某些字段的对象(书籍)数组,因此我使用node-isbn 模块来获取丢失的数据。但是,我无法持久保存对象的更新。下面是一些示例代码:
const isbn = require('node-isbn');
var books = []; // assume this is filled in elsewhere
books.forEach(function(item) {
if (item.publication_year == '' ||
item.num_pages == '') {
isbn.provider(['openlibrary', 'google'])
.resolve(item.isbn)
.then(function (book) {
item.num_pages = book.pageCount;
item.publication_year = book.publishedDate.replace( /^\D+/g, '');
}).catch(function (err) {
console.log('Book not found', err);
});
}
console.log(item)
});
但是,控制台日志显示 num_pages 和 publication_year 字段仍然为空。我该如何解决这个问题?
【问题讨论】:
-
似乎正确.. 只有你在异步返回之前登录控制台
标签: javascript node.js