我想的就是一次读出所有数据 然后用JS画表格,前面加判断 if parntid<>0 and rootid=i 输出str1=classname i该怎么判断我还没想出来,谁指点一下,用rootid判断该调用哪条数据 if parntid=0 输出str=<li><p>classname<p><p>str1</p></li> 画表格的时候可以这样画, <ul> str </ul>我脑子乱了,谁有好的思路?
笨方法,共参考: <body> <style> ul{list-style:disc} li{padding:5px 0} p {margin:0 3px; padding:3px; border:1px solid #ccc; display:inline} </style> <ul id="ul"></ul> <script> var arr = [ {classId:'2', className:'程序开发教程', parentPath:'0', arrChildId:'2,11'}, {classId:'11', className:'ASP教程', parentPath:'0,2', arrChildId:'11'}, {classId:'1', className:'网页制作教程', parentPath:'0', arrChildId:'1,6'}, {classId:'6', className:'Dreamweaver', parentPath:'0,1', arrChildId:'6'} ];var lis = []; var x = 0; function getList(){ for(var i=0; i<arr.length; i++) if(arr[i].parentPath == 0){ lis[x] = []; lis[x].push(arr[i].className); var chs = arr[i].arrChildId.split(','); chs.shift(); getChild(lis[x],chs); x++; continue; } }function getChild(lis,ids){ if(!ids.length)return; var ids = ids.join('|'); var reg = new RegExp('^'+ids+'$'); for(var i=0; i<arr.length; i++) if(reg.test(arr[i].classId)){ lis.push(arr[i].className); var chs = arr[i].arrChildId.split(','); chs.shift(); getChild(lis, chs); continue; } } getList(); var ul = document.getElementById('ul'); for(var i=0; i<lis.length; i++){ var li = document.createElement('li'); for(var n=0; n<lis[i].length; n++) li.innerHTML += '<p>'+lis[i][n]+'</p>'; ul.appendChild(li); } </script> </body>
有没有效率高点的代码?用变量来判断,我这有段ASP代码,差不多就是这个意思,哪位能帮我写成js的代码? <% dim rs,sql,tmpa,str set rs = server.CreateObject("adodb.recordset") sql = "select ClassName,RootID from PE_Class where channelID=1002 order by RootID,ParentPath" rs.open sql,conn,1,1 str = " <li>" if not rs.eof then tmpa = rs("ROOtID") end if do while not rs.eof if tmpa <>rs("RootID") then tmpa = rs("ROOtID") str = str & " </li> <li> <p>" & rs("ClassName") & " </p>" else str = str & " <p>" & rs("ClassName") & " </p>" end if rs.movenext loop rs.close response.Write " <ul>" & str & " </ul>" %>
然后用JS画表格,前面加判断
if parntid<>0 and rootid=i 输出str1=classname
i该怎么判断我还没想出来,谁指点一下,用rootid判断该调用哪条数据
if parntid=0 输出str=<li><p>classname<p><p>str1</p></li>
画表格的时候可以这样画,
<ul>
str
</ul>我脑子乱了,谁有好的思路?
<body>
<style>
ul{list-style:disc}
li{padding:5px 0}
p {margin:0 3px; padding:3px; border:1px solid #ccc; display:inline}
</style>
<ul id="ul"></ul>
<script>
var arr = [
{classId:'2', className:'程序开发教程', parentPath:'0', arrChildId:'2,11'},
{classId:'11', className:'ASP教程', parentPath:'0,2', arrChildId:'11'},
{classId:'1', className:'网页制作教程', parentPath:'0', arrChildId:'1,6'},
{classId:'6', className:'Dreamweaver', parentPath:'0,1', arrChildId:'6'}
];var lis = [];
var x = 0;
function getList(){
for(var i=0; i<arr.length; i++)
if(arr[i].parentPath == 0){
lis[x] = [];
lis[x].push(arr[i].className);
var chs = arr[i].arrChildId.split(',');
chs.shift();
getChild(lis[x],chs);
x++;
continue;
}
}function getChild(lis,ids){
if(!ids.length)return;
var ids = ids.join('|');
var reg = new RegExp('^'+ids+'$');
for(var i=0; i<arr.length; i++)
if(reg.test(arr[i].classId)){
lis.push(arr[i].className);
var chs = arr[i].arrChildId.split(',');
chs.shift();
getChild(lis, chs);
continue;
}
}
getList();
var ul = document.getElementById('ul');
for(var i=0; i<lis.length; i++){
var li = document.createElement('li');
for(var n=0; n<lis[i].length; n++)
li.innerHTML += '<p>'+lis[i][n]+'</p>';
ul.appendChild(li);
}
</script>
</body>
<%
dim rs,sql,tmpa,str
set rs = server.CreateObject("adodb.recordset")
sql = "select ClassName,RootID from PE_Class where channelID=1002 order by RootID,ParentPath"
rs.open sql,conn,1,1
str = " <li>"
if not rs.eof then tmpa = rs("ROOtID") end if
do while not rs.eof
if tmpa <>rs("RootID") then
tmpa = rs("ROOtID")
str = str & " </li> <li> <p>" & rs("ClassName") & " </p>"
else
str = str & " <p>" & rs("ClassName") & " </p>"
end if
rs.movenext
loop
rs.close
response.Write " <ul>" & str & " </ul>"
%>