Javascript 只在JSON数据的最后一部分上执行函数

Javascript 只在JSON数据的最后一部分上执行函数,javascript,jquery,json,roblox,Javascript,Jquery,Json,Roblox,我试图在JSON数据的每个成员上运行一个函数。不过,它只在最后一部分运行它。代码很混乱,因为我已经添加和删除调试几个小时了。我是noob和JS:( 这是checkIt函数代码:(checkBlacklist.php返回true或false) 下面是通过JSON的代码 $.get(“http://robloxplus.com:2052/inventory?username=iTracking)。成功(功能(r){ for(r.data.hat.data中的变量id){ $(“h2”).empty(

我试图在JSON数据的每个成员上运行一个函数。不过,它只在最后一部分运行它。代码很混乱,因为我已经添加和删除调试几个小时了。我是noob和JS:(

这是checkIt函数代码:(checkBlacklist.php返回true或false)

下面是通过JSON的代码

$.get(“http://robloxplus.com:2052/inventory?username=iTracking)。成功(功能(r){
for(r.data.hat.data中的变量id){
$(“h2”).empty();//删除“项目加载”标题
如果(r.data.hat.data[id].rap>1000&&r.data.hat.data[id].rap<5000){
//这里是混乱的地方,真的很奇怪。
log(r.data.hat.data[id].name);
var selectedNope=0;
选中它(r.data.hat.data[id].id,函数(){
selectedNope=nope;
nope=0;
console.log(为“+r.data.hat.data[id].name”选择了nope+”;
如果(selectedNope==1){
$(“body”).append(“RAP:+r.data.hat.data[id].RAP+“手动价格集”);
}else{console.log(“它不是1,它是“+r.data.hat.data[id].name]”的“+selectedNope+”;)
});
} 
});
好的,那么它的作用是:

输出:

在检查之前,在console.log上输出所有帽子名称

一旦进入checkIt,它只输出一个ID,即JSON列表中的最后一个ID 被称为蒸汽朋克特里科恩两次,这需要更换的两个帽子,实际上应该在那里

只附加蒸汽朋克三角犬

蒸汽朋克三角犬甚至不应该进入if声明中

if (r.data.hat.data[id].rap > 1000 && r.data.hat.data[id].rap < 5000) { 
if(r.data.hat.data[id].rap>1000&&r.data.hat.data[id].rap<5000){
基本上,它会把原本应该在那里的东西换成不应该在那里的东西(蒸汽朋克特里科恩)


抱歉,如果这太让人困惑了,我已经尽力解释了。

我想你的问题就在于此。(另请参见:)

此修复程序可能会起作用:

function checkHat(hat) {
    if (hat.rap > 1000 && hat.rap < 5000) {
        $.post("checkBlacklist.php?id=" + hat.id, function (data) {
            console.log(data + " for " + hat.name);
            if (data == "false") {
                $("body").append("<center><div class='itemContainer_blue'><div class='itemName'><a href='http://www.roblox.com/---item?id=" + hat.id + "'>" + hat.name + "</a></div><div class='itemRap'>RAP: " + hat.rap + "</div><div class='itemImage'> <a href='#' title='Item Name'> <center><img src='" + hat.image + "' alt='itemImage'/></center></a></div> <div class='itemPrice'>Manual Price Set</div></div></center>");
            } else {
                console.log("it was not 1, it was " + data + " for " + hat.name);
            }
        });
    }
}

$.get("http://robloxplus.com:2052/inventory?username=iTracking").success(function (r) {
    $("h2").empty();
    for (var id in r.data.hat.data) {
        checkHat(r.data.hat.data[id]);
    }
});
功能检查帽(hat){
如果(hat.rap>1000&&hat.rap<5000){
$.post(“checkBlacklist.php?id=“+hat.id,函数(数据)){
console.log(数据+”表示“+hat.name”);
如果(数据==“假”){
$(“正文”).append(“RAP:+hat.RAP+“手动价格集”);
}否则{
log(“不是1,而是“+data+”表示“+hat.name”);
}
});
}
}
$.get(”http://robloxplus.com:2052/inventory?username=iTracking)。成功(功能(r){
$(“h2”).empty();
for(r.data.hat.data中的变量id){
checkHat(r.data.hat.data[id]);
}
});
if (r.data.hat.data[id].rap > 1000 && r.data.hat.data[id].rap < 5000) { 
function checkHat(hat) {
    if (hat.rap > 1000 && hat.rap < 5000) {
        $.post("checkBlacklist.php?id=" + hat.id, function (data) {
            console.log(data + " for " + hat.name);
            if (data == "false") {
                $("body").append("<center><div class='itemContainer_blue'><div class='itemName'><a href='http://www.roblox.com/---item?id=" + hat.id + "'>" + hat.name + "</a></div><div class='itemRap'>RAP: " + hat.rap + "</div><div class='itemImage'> <a href='#' title='Item Name'> <center><img src='" + hat.image + "' alt='itemImage'/></center></a></div> <div class='itemPrice'>Manual Price Set</div></div></center>");
            } else {
                console.log("it was not 1, it was " + data + " for " + hat.name);
            }
        });
    }
}

$.get("http://robloxplus.com:2052/inventory?username=iTracking").success(function (r) {
    $("h2").empty();
    for (var id in r.data.hat.data) {
        checkHat(r.data.hat.data[id]);
    }
});