nodejs中的循环仅返回最后一个值

时间:2015-05-07 07:38:38

标签: javascript node.js loops

我无法在我的生活中找出nodejs中的异步流。我目前正在尝试从服务器获得响应。这没问题。并使用该响应来验证是否将语句添加到数组(如果为true)。并忽略如果是假的。目前这是我用于测试。并且在日志中我有一个声明,其响应为false,另一个声明为true。但两者都使用相同的地址。

		var test = Object.keys(addressAmounts);
		test.forEach(function(address) {
		daemon.cmd('validateaddress', [address], function (results) {
			var validWorkerAddress = results[0].response.isvalid;
		//if (validWorkerAddress != "false") {
		          //console.log("\n\n\n\n Worker: " + w + " GETS COINS! " + coin + "\n\n\n");
		//} else {
		          //console.log("\n\n\n\n Worker: " + w + " NO COINS BRA! " + coin + "\n\n\n");
		//}
		//console.log("Test for " + w + " is " + results[0].response.isvalid);
		if (validWorkerAddress != 'false') {
		  console.log("Test for " + address + " was ok on " + coin +' isvalid:'+ validWorkerAddress + "\n\n\n");
		} else {
		  console.log("Test for " + address + " was NOT ok\n\n\n");
		}
  		      });
		});

0 个答案:

没有答案