这可能吗?1 for 循环 3 语句?
for(var i =0; i< aObj.length;i++)
(var a =0; a< bObj.length;a++)
(var b =0; b< cObj.length;b++){
//sOME CODE HERE
}
这可能吗?1 for 循环 3 语句?
for(var i =0; i< aObj.length;i++)
(var a =0; a< bObj.length;a++)
(var b =0; b< cObj.length;b++){
//sOME CODE HERE
}
不,这是无效的 javascript 语法。根据您的要求,您可以使用 3 个嵌套的 for 循环或使它们连续。
例如:
for(var i = 0; i < aObj.length; i++) {
for(var a = 0; a < bObj.length; a++) {
for(var b = 0; b < cObj.length; b++) {
// some code here
}
}
}
或者:
for(var i = 0; i < aObj.length; i++) {
// some code here
}
for(var a = 0; a < bObj.length; a++) {
// some code here
}
for(var b = 0; b < cObj.length; b++) {
// some code here
}
但是,这将再次取决于您需要对这些变量做什么。
我认为tat是不可能的更好的选择:
for(var i =0; i< aObj.length;i++){
for(var a =0; a< bObj.length;a++){
for(var b =0; b< cObj.length;b++){
//sOME CODE HERE
}
}
}
this is my actual Code guys..Im getting the last items for Name,Code and Category not per items in array
var CodeObj=new Array(); var NameObj=new Array(); new aObj = new Array();
var CatObj=new Array(); var Codeindex= 0;
var Nameindex= 0; var Catindex= 0; aindex = 0;
$(req.responseText).find('Name').each(function(){
NameObj[Nameindex] = $(this).text();
Nameindex +=0;
for(var i =0; i< NameObj.length;i++){
$(this).append(NameObj[i]+"<br/>");
} //1st loop to get the Name
})
$(req.responseText).find('Code').each(function(){
CodeObj[Codeindex] = $(this).text();
Codeindex +=0;
for(var a =0; a< CodeObj.length;a++){
$(this).append(CodeObj[a]+"<br/>");
} //2nd loop to get the Code
});
$(req.responseText).find('Category').each(function(){
CatObj[Catindex] = $(this).text();
Catindex +=0;
for(var b =0; b< CatObj.length;b++){
$(this).append(CatObj[b]+"<br/>");
} //3rd loop to get the category
});
//codes to append in list view
var $content = $('<li><a href="#"><img src="../../img/album-bb.jpg"><h3>Name: '+ NameObj[i] + '</h3><p>Code: '+ CodeObj[a] + '</p><p>Category: '+ CatObj[b] + '</p></a><a href="#purchase" data-rel="popup" data-position-to="window" data-transition="pop">Add to favorites</a></li>');
$('#RecipeList').append($content).listview('refresh');