相互检查数组变量

时间:2022-03-25 13:28:18
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);

Basically I think everything is actually working as it should. But the arrays both the carpetArray and the object array pulled from the php file($carpets) are quite long, like a hundred or so variables in them. When I try to run the code I get an error message in the console saying error in javascript console, functionality might be affected. I'm guessing the console doesn't like showing me all the numbers, but for some reason when I run the function nothing happens.

基本上我认为一切都在按照应有的方式运作。但是数组中的carpetArray和从php文件($ carpets)中提取的对象数组都很长,就像它们中的大约一百个变量一样。当我尝试运行代码时,我在控制台中收到错误消息,说明javascript控制台中的错误,功能可能会受到影响。我猜控制台不喜欢向我显示所有数字,但出于某种原因,当我运行该功能时没有任何反应。

Following this bit in the script is another $.each iterater that displays the content of carpets into a div, but it's not working.

脚本中的这一位是另一个$ .each迭代器,它将地毯的内容显示为div,但它不起作用。

Any help would be appreciated, thanks.

任何帮助将不胜感激,谢谢。

2 个解决方案

#1


seems that you're missing a ) on line 6 and carpetArray and list don't exist

似乎你在第6行缺少a)而且rugArray和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);

#2


Replace $carpet with data.

用数据替换$ carpet。

And you are missing ")" on the console.log command.

你在console.log命令中缺少“)”。

#1


seems that you're missing a ) on line 6 and carpetArray and list don't exist

似乎你在第6行缺少a)而且rugArray和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);

#2


Replace $carpet with data.

用数据替换$ carpet。

And you are missing ")" on the console.log command.

你在console.log命令中缺少“)”。