var carpets = [];
$.get("pullCarpets.php", function($carpets){
$.each($carpets, function(i, item){
console.log(item.id);
for(var j = 0; j < carpetArray.length; j++){
console.log(carpetArray[j];
if(carpetArray[j] == item.id){
list.push(item);
}
}
});
}, "json");
console.log(carpets);
基本上我认为一切都在按其应有的方式进行。但是从 php 文件($carpets)中提取的地毯数组和对象数组都相当长,其中有一百个左右的变量。当我尝试运行代码时,我在控制台中收到一条错误消息,指出 javascript 控制台中出现错误,功能可能会受到影响。我猜控制台不喜欢向我显示所有数字,但由于某种原因,当我运行该函数时什么也没有发生。
脚本中的这一点后面是另一个 $.each 迭代器,它将地毯的内容显示到 div 中,但它不起作用。
如有任何帮助,我们将不胜感激,谢谢。
最佳答案
似乎您在第 6 行缺少 )
,并且 carpetArray
和 list
不存在
var carpets = [];
var list = [];
$.get("pullCarpets.php", function($carpets){
$.each($carpets, function(i, item){
console.log(item.id);
for(var j = 0; j < carpets.length; j++){
console.log(carpets[j]);
if(carpets[j] == item.id){
list.push(item);
}
}
});
}, "json");
console.log(carpets);
关于javascript - 相互检查数组变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004521/