api 回调的输出以显示第一个对象的数据
output of api callback to show data of the first object
我正在循环中执行 api 回调以获取值的最新状态。api 调用和循环正在工作,但它没有向我显示第一个的数据返回的对象.. 相反,它向我显示了最后一个对象的数据。循环的原因是因为可能返回了多个对象,但我希望输出按对象 0 然后对象 1 等的顺序通过它们..
这是来自 firebug 的屏幕截图,显示了两个对象及其各自的数据点。如您所见,首先显示对象 0,然后显示对象 1。
这是我在页面上输出数据的代码。此代码位于 if 语句中,其中 status = "RESULT" - 您无法从下面的代码中分辨出来,但这两个对象都符合该条件
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
以上代码的问题在于输出的顺序。它显示第二个对象的数据,因为我需要它给我第一个对象的输出。
-- 更新--
似乎按照 Barmer 在循环中添加 IF 的建议工作
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
if (endpoint.statusMessage == "In progress") {
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
}
}
测试循环中的状态。由于您只想显示正在进行的第一个端点,因此您应该在找到它时跳出循环。
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
if (endpoint.statusMessage == "In progress") {
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
break;
}
}
我正在循环中执行 api 回调以获取值的最新状态。api 调用和循环正在工作,但它没有向我显示第一个的数据返回的对象.. 相反,它向我显示了最后一个对象的数据。循环的原因是因为可能返回了多个对象,但我希望输出按对象 0 然后对象 1 等的顺序通过它们..
这是来自 firebug 的屏幕截图,显示了两个对象及其各自的数据点。如您所见,首先显示对象 0,然后显示对象 1。
这是我在页面上输出数据的代码。此代码位于 if 语句中,其中 status = "RESULT" - 您无法从下面的代码中分辨出来,但这两个对象都符合该条件
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
以上代码的问题在于输出的顺序。它显示第二个对象的数据,因为我需要它给我第一个对象的输出。
-- 更新--
似乎按照 Barmer 在循环中添加 IF 的建议工作
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
if (endpoint.statusMessage == "In progress") {
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
}
}
测试循环中的状态。由于您只想显示正在进行的第一个端点,因此您应该在找到它时跳出循环。
for (var i = 0; i < response.endpoints.length; i++) {
var endpoint = response.endpoints[i];
if (endpoint.statusMessage == "In progress") {
//console.log(endpoint);
$pending0.html("<br><b>Server Name: </b>" + endpoint.serverName + "<br><b>Status: </b>" + endpoint.statusMessage + "<br><b>Progress: </b>" + endpoint.statusDetailsMessage);
break;
}
}