Javascript nodejs中的承诺,while循环不工作

Javascript nodejs中的承诺,while循环不工作,javascript,node.js,promise,Javascript,Node.js,Promise,我有一个写了很多承诺的测试脚本。它在nodejs上 之前所有的值都是硬编码的,但现在我想从JSON中解析数据 它也包含数组 问题是while循环被执行,最糟糕的是我没有得到任何输出 请在下面查找代码 假设我有一个 lib.connect().then(lib.wipedb).then(lib.init).then(lib.createDev).then(lib.creat‌​eDeviceModel).then(lib.createDeviceModal2).then(lib.createU).

我有一个写了很多承诺的测试脚本。它在nodejs上 之前所有的值都是硬编码的,但现在我想从JSON中解析数据 它也包含数组

问题是while循环被执行,最糟糕的是我没有得到任何输出

请在下面查找代码

假设我有一个

lib.connect().then(lib.wipedb).then(lib.init).then(lib.createDev).then(lib.creat‌​eDeviceModel).then(lib.createDeviceModal2).then(lib.createU).then(lib.createU2).t‌​hen(function() { return lib.createOrg("Park Hotels"); }).then(function() { return lib.createDeviceGroup("Okinawa"); }).then(function()
{
   var i=0;
   while(i!=100)
   {
     //Add Virtual Devices 100 Times
     // problem is i cannot add devices as the loop executes and does not
     // For Promises . How could i add 100 Users using the loop
     // Or If there are any another way to achieve this.
      // Loop is not working here but i need to add 100 

   }

}).then......
更新

我有一个JS文件,它有所有的函数,所有这些都是基于承诺的

some.Db().then(some.wipeAll).then(some.getALL).then(some.createUser).
then(function()
{  
  some.addUser("abc");

}.then(function()
{

  some.addUser("def");  //Till 50 Times

}.then(function()
{

  some.showUser("sah");   //Till 50 Times

}.then(function()
{

  some.emulateuser("name");   //till 50 Times

}
上述代码工作正常,值始终是硬编码的,重复上述过程直到100个用户。这是对编程模式的浪费

因此,我编写了一个JSON obj,其中包含数组中的所有用户数据,并重写了如下代码

lib.connect().then(lib.wipedb).then(lib.init).then(lib.createDev).then(lib.creat‌​eDeviceModel).then(lib.createDeviceModal2).then(lib.createU).then(lib.createU2).t‌​hen(function() { return lib.createOrg("Park Hotels"); }).then(function() { return lib.createDeviceGroup("Okinawa"); }).then.......
问题是它根本不起作用,当打开时,我在Db或html中看不到任何东西。由于使用了手动数据输入的承诺,它产生了很多问题。我就是不能在while循环中使用JSON
让thsi代码正常工作。请提供帮助。

您的addUser、showUser和emulateuser方法是否异步并返回承诺?为什么在第二个示例中只使用addUser?有些.addUser是异步的,并实现了承诺。问题是它是由一个年轻人写的,他写了50-100遍。现在我们必须增加1000多个用户。我们不能这样做。其他文件不能被篡改,我只能控制这个。我必须使用while循环添加数据/用户,但是循环执行时不会等待承诺完成。当然,你不会在任何地方等待那些addUser承诺。但是,原来的代码,只是重复了statment也没有,所以我怀疑它以前的工作?请张贴准确的原始代码从50到至少5行剥离!请发电子邮件给我。我会寄给你的。
some.Db().then(some.wipeAll).then(some.getALL).then(some.createUser).
    then(function()
    {  
      var i=0;
      var user =  // get all user details and loop thorogh
      while(i!=user.length)
     {
       some.addUser(user.name);
       i+=1;
     }

    }.then(function()
    {

      var i=0;
      var user =  // get all user details and loop thorogh
      while(i!=user.length)
     {
       some.addUser(user.name);
       i+=1;
     }

    }.then(function()
    {

     var i=0;
      var user =  // get all user details and loop thorogh
      while(i!=user.length)
     {
       some.addUser(user.name);
       i+=1;
     }

    }.then(function()
    {

     var i=0;
      var user =  // get all user details and loop thorogh
      while(i!=user.length)
     {
       some.addUser(user.name);
       i+=1;
     }

    }