如何在json而不是for循环中使用每个? [英] how to use for each in json instead of for loop?
本文介绍了如何在json而不是for循环中使用每个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在JSON中使用每个而不是for循环。我目前正在使用循环,但它不能正常工作。这是我的代码:
for (i = 0 ; i < = 1000 ; i ++){
$( #ddlType)。val(data.d [i] .TypeID );
SetTypeDetails();
$( #lblTypeValue)。text(data.d [i] .TypeName );
$( #lblcodeValue)。text(data.d [i] .Code );
$( #cbTypeActive)。attr( 选中,data.d [i] .active);
}
这里setTypeDetails()是一个用于创建和附加div的函数。
解决方案
( #ddlType)。val(data.d [i] .TypeID);
SetTypeDetails();
( #lblTypeValue)。text(data.d [i] .TypeName);
( #lblcodeValue跨度>)文本(data.d [I]。代码);
Hi,
I need to use for each in JSON instead of for loop. I am currently using for loop but its not working well. Here is my code:
for (i = 0; i <= 1000; i++) {
$("#ddlType").val(data.d[i].TypeID);
SetTypeDetails();
$("#lblTypeValue").text(data.d[i].TypeName);
$("#lblcodeValue").text(data.d[i].Code);
$("#cbTypeActive").attr("checked", data.d[i].active);
}
Here setTypeDetails() is a function for create and appending the div.
解决方案
("#ddlType").val(data.d[i].TypeID); SetTypeDetails();
("#lblTypeValue").text(data.d[i].TypeName);
("#lblcodeValue").text(data.d[i].Code);
这篇关于如何在json而不是for循环中使用每个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文