<i id='U5Yqk'><tr id='U5Yqk'><dt id='U5Yqk'><q id='U5Yqk'><span id='U5Yqk'><b id='U5Yqk'><form id='U5Yqk'><ins id='U5Yqk'></ins><ul id='U5Yqk'></ul><sub id='U5Yqk'></sub></form><legend id='U5Yqk'></legend><bdo id='U5Yqk'><pre id='U5Yqk'><center id='U5Yqk'></center></pre></bdo></b><th id='U5Yqk'></th></span></q></dt></tr></i><div id='U5Yqk'><tfoot id='U5Yqk'></tfoot><dl id='U5Yqk'><fieldset id='U5Yqk'></fieldset></dl></div>
  • <small id='U5Yqk'></small><noframes id='U5Yqk'>

  • <legend id='U5Yqk'><style id='U5Yqk'><dir id='U5Yqk'><q id='U5Yqk'></q></dir></style></legend>

      <tfoot id='U5Yqk'></tfoot>
        <bdo id='U5Yqk'></bdo><ul id='U5Yqk'></ul>
      1. Promise.all(...).spread 不是并行运行 Promise 时的函数

        时间:2023-09-03

            <tbody id='T18rG'></tbody>

              <bdo id='T18rG'></bdo><ul id='T18rG'></ul>

              <tfoot id='T18rG'></tfoot>
            • <small id='T18rG'></small><noframes id='T18rG'>

                <i id='T18rG'><tr id='T18rG'><dt id='T18rG'><q id='T18rG'><span id='T18rG'><b id='T18rG'><form id='T18rG'><ins id='T18rG'></ins><ul id='T18rG'></ul><sub id='T18rG'></sub></form><legend id='T18rG'></legend><bdo id='T18rG'><pre id='T18rG'><center id='T18rG'></center></pre></bdo></b><th id='T18rG'></th></span></q></dt></tr></i><div id='T18rG'><tfoot id='T18rG'></tfoot><dl id='T18rG'><fieldset id='T18rG'></fieldset></dl></div>

                  <legend id='T18rG'><style id='T18rG'><dir id='T18rG'><q id='T18rG'></q></dir></style></legend>
                  本文介绍了Promise.all(...).spread 不是并行运行 Promise 时的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用 sequelize 并行运行 2 个 Promise,然后在 .ejs 模板中呈现结果,但我收到此错误:

                  I'm trying to run 2 promises in paralel with sequelize, and then render the results in a .ejs template, but I'm receiving this error:

                   Promise.all(...).spread is not a function
                  

                  这是我的代码:

                  var environment_hash = req.session.passport.user.environment_hash;
                  var Template  = require('../models/index').Template;
                  var List      = require('../models/index').List;
                  
                  var values = { 
                      where: { environment_hash: environment_hash,
                               is_deleted: 0 
                          }                    
                  };
                  
                  template = Template.findAll(values);
                  list = List.findAll(values);
                  
                  
                  Promise.all([template,list]).spread(function(templates,lists) {
                  
                      res.render('campaign/create.ejs', {
                          templates: templates,
                          lists: lists
                      });
                  
                  });
                  

                  我该如何解决这个问题?

                  How can I solve thhis?

                  推荐答案

                  因为它解决了你的问题,所以我会把我的评论变成答案.

                  I'll make my comment into an answer since it solved your issue.

                  .spread() 不是标准的 promise 方法.它在 Bluebird Promise 库中可用.您包含的代码没有显示这一点.三种可能的解决方案:

                  .spread() is not a standard promise method. It is available in the Bluebird promise library. Your code you included does not show that. Three possible solutions:

                  直接访问数组值

                  您可以只使用 .then(results => {...}) 并以 results[0]results[1 的形式访问结果].

                  You can just use .then(results => {...}) and access the results as results[0] and results[1].

                  包括 Bluebird Promise 库

                  您可以包含 Bluebird 承诺库,以便您可以访问 .spread().

                  You can include the Bluebird promise library so you have access to .spread().

                  var Promise = require('bluebird');
                  

                  在回调参数中使用解构

                  在最新版本的 nodejs 中,您还可以使用解构赋值来消除对 .spread() 的需求,如下所示:

                  In the latest versions of nodejs, you could also use destructuring assignment which kind of removes the need for .spread() like this:

                  Promise.all([template,list]).then(function([templates,lists]) {
                      res.render('campaign/create.ejs', {templates, lists});
                  });
                  

                  这篇关于Promise.all(...).spread 不是并行运行 Promise 时的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从数组中创建表中的多行? 下一篇:sequelize Model.hasOne 错误:模型未关联到 ModelTwo

                  相关文章

                  <i id='QAN93'><tr id='QAN93'><dt id='QAN93'><q id='QAN93'><span id='QAN93'><b id='QAN93'><form id='QAN93'><ins id='QAN93'></ins><ul id='QAN93'></ul><sub id='QAN93'></sub></form><legend id='QAN93'></legend><bdo id='QAN93'><pre id='QAN93'><center id='QAN93'></center></pre></bdo></b><th id='QAN93'></th></span></q></dt></tr></i><div id='QAN93'><tfoot id='QAN93'></tfoot><dl id='QAN93'><fieldset id='QAN93'></fieldset></dl></div>

                      <bdo id='QAN93'></bdo><ul id='QAN93'></ul>

                    <small id='QAN93'></small><noframes id='QAN93'>

                  1. <tfoot id='QAN93'></tfoot>

                    1. <legend id='QAN93'><style id='QAN93'><dir id='QAN93'><q id='QAN93'></q></dir></style></legend>