import translate from 'translate';
...
export const search = async (req, res) => {
...
const makeDictionaryTree = async elem => {
let newArr = []
for (let e of elem) {
let obj = new Object();
obj.pinyin = e.pinyin;
obj.definitions = e.definitions;
for (let e of obj.definitions) {
console.dir(e, ' = ')
e = await translate(e, { to: 'ru', engine: 'google', key: process.env.TRANSLATE_KEY })
console.dir(e)
}
newArr.push(obj)
}
return newArr
}
...
words = newArr.map(e => {
let newE = new Object();
newE.character = e;
newE.decomp = decomp.lookup(e);
newE.decomp2 = hanzi.decompose(e, 1);
newE.decomp3 = hanzi.decompose(e, 2);
newE.entries = makeDictionaryTree(getEntries(e));
return newE;
})
...
console.log(words)
res.render("search", { pageTitle: "Search", searchingBy, newUrl, uniqueCharSet, words: words })
};
console.log(words[0].entries) Выводит Promise { }
Получается скрипт не дожидается функции makeDictionaryTree и сразу рендерит страницу
[
{
character: '觉',
decomp: { label: '觉', children: [Array] },
decomp2: { character: '觉', components: [Array] },
decomp3: { character: '觉', components: [Array] },
entries: Promise { <pending> }
}
]