js里怎么遍历List

JavaScript021

js里怎么遍历List,第1张

代码如下:

<SCRIPT language="javaScript">

var d = new dTree('d')

d.add(1,-1,"用户组","","","kunFrame")

<%

Object obj =request.getAttribute("custgrouplist")

List groupList = null

int count =2

String groupName = ""

int groupId = 0

if(obj!=null)

{

groupList = (List)obj

}

if(groupList!=null&&groupList.size()>0)

{

for(int i=0i<groupList.size()i++)

{

CustGroup am = (CustGroup)groupList.get(i)

groupName = am.getVgroupName()

groupId = am.getGroupId()

// System.out.println(groupId)

%>

d.add(<%=count%>,1,'<%=groupName%>','<%=request.getContextPath()%>/showAreaByGroup.action?groupId=<%=groupId%>',"","kunFrame")

<%

count++

}

}

%>

document.write(d)

</SCRIPT>

$.post('/wjdc/admin/wxWjTm/chooseTm.do', {

    wjId: wjId

}, function(res) {

    // [{'id':'1','sxTm':'性别'},{'id':'2','sxTm':'省份'}]

    var sel = $("select")

    for (var i = 0 i < res.length i++) {

        sel.append("<option value=" + res[i].id + ">" + res[i].sxTm + "</option>")

    }

})