[英]Rendering multiple instances in Handlebars+Express+Nodejs
please help me with following: how to render multiple instances which are comming from anydata base (in my case from Gcloud datastore, before it was MongoDB but it does not actually matter), as i understand Handlebars can accept/parse objects or array or objects, so now im doing this way Im importing functions that returns a promise 请帮助我以下内容:如何呈现来自任何数据库的多个实例(以我的情况为例,来自Gcloud数据存储,这是在MongoDB之前,但实际上并不重要),据我了解,把手可以接受/解析对象或数组或对象,因此现在我以这种方式进行即时通讯,即导入了返回承诺的函数
const someFunction = require('from somewhere');
somedatabase query (err, apiResponse) => {
>>> someFunction ().then(someFunctionResponse=> {
res.render('index', {
x: apiResponse,
y: someFunctionResponse,
});
});
})
im using one inside other, Is this a right way ? 我在彼此内部使用,这是正确的方法吗? I dont see any other way to resolve promise and pass it to res.render
我看不到任何其他方法来解决诺言并将其传递给res.render
It works fine but just to be sure / more professional 它工作正常,但只是为了确保/更加专业
Answer is to use Promise.all()
thats it. 答案是使用
Promise.all()
。 In case 如果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.