我感觉这是一个简单的修复,但我不能为我的生活找到错误。当我运行此脚本检查JSON文件中的数组以获取布尔值数据时,我总是收到未定义的值。我把它全部放入小提琴中。滚动到JS部分的底部。以下是不想切换标签页的代码。将JSON传递给循环
$.ajax({
url: "/echo/json/",
data: data,
type: "POST",
success: function (response) {
//Loop Start
for (var fund in response.fundClass){
console.log(fund.class);
if(fund.xbrl == false){
$(fund.class + " .xbrl").addClass(".hide");
}
if(fund.prospSum == false){
$(fund.class + " .prospSum").addClass(".hide");
}
}
//Loop End
}
});
当你使用'for..in'时,你会得到*键*而不是数值。 'console.log(response.fundClass [fund] .class);'尽管由于'response.fundClass'是一个*数组*,所以我建议*不使用'for..in'。对于(var i = 0; i
旁注:不要使用'class'作为标识符,它的保留 – Satpal