我从后台获取的分类数据,各节点的类名都在一张表中。先找到所有父节点填充进去了,现在要找到子节点填充到相应的父节点中怎么做啊?
for(var i=0;i<temp.message.List.length;i++)
{
if(parseInt(temp.message.List[i].ParentID)==0)
{
contentParent+="<li class=\"item\" id=\"category0\" onmouseout=\"this.className=\'item\'\"onmouseover=\"this.className=\'item hover\'\" ><div class=\"icon\" id="+temp.message.List[i].TypeID+"><a href=\"#\" class=\"no-left-products\"><cite class=\"care-list title-img\"></cite> </a><a href=\"#\"><>"+temp.message.List[i].TypeName+"</></a></div>"
}
}
jq("#category").append(contentParent);//这是获取父节点并填充下面我想向代码中的绿色DIV部分填充子节点,求指点!
for(var i=0;i<temp.message.List.length;i++)
{
if(parseInt(temp.message.List[i].ParentID)==0)
{
contentParent+="<li class=\"item\" id=\"category0\" onmouseout=\"this.className=\'item\'\"onmouseover=\"this.className=\'item hover\'\" ><div class=\"icon\" id="+temp.message.List[i].TypeID+"><a href=\"#\" class=\"no-left-products\"><cite class=\"care-list title-img\"></cite> </a><a href=\"#\"><>"+temp.message.List[i].TypeName+"</></a></div>"
}
}
jq("#category").append(contentParent);//这是获取父节点并填充下面我想向代码中的绿色DIV部分填充子节点,求指点!
直接
$("#"+temp.message.List[i].TypeID).append('要追加进div尾部的内容');
上面这条不用一定要写去最后吧contentParent='……'
jq("#category").append(contentParent);//这样就行了呀
然后在这后面,就继续填充你说的填充子节点,已经是在for循环中了,只接获取内容,填充就是了
要写在子节点被填充进去的后台jq("#category").append(contentParent);//这是获取父节点并填充
上面这条不用一定要写去最后吧contentParent='……'
jq("#category").append(contentParent);//这样就行了呀
上面不就是已经实时填充了。contentParent你不用+=做连接字符串的操作,就让它成为一个局部变量。每生成一个,就直接填充一个,和你最后一起再填充有没有不同然后在这后面,就继续填充你说的填充子节点,已经是在for循环中了,只接获取内容,填充就是了