我认为您仍然可以异步执行此操作。首先,您需要从对象中获取所有属性:
//Gather up all the properties;
var properties = [];
for(var property in object) if(object.hasOwnProperty(property) {
properties.push(property);
}
//Array of results
var resultsArray = [];
//This is a named, self-invoked function that basically behaves like a loop. The
//loop counter is the argument "i", which is initially set to 0. The first if
//is basically the loop-termination condition. If i is greater than the
//total number of properties, we know that we're done.
//
//The success handler of the ajax call is where the loop is advanced. This is also
//where you can put your if condition to check if something is true, so that you
//can insert the data into the results array. At the end of the success handler,
//you basically call the named self-invoked function, but this time with the
//loop counter incremented.
(function iterateOverProperties(i) {
if(i < properties.length) {
var property = properties[i];
var value = object[property];
//assuming jQuery just for demonstration
jQuery.ajax({
url: "someurl",
data: value;
success: function(data) {
if(something is true) {
resultArray.push(data);
}
iterateOverProperties(++i);
}
});
} else {
res(resultArray);
}
})(0);