this how it look when we debug和 this how we wanted to look like 我有一个foreach循环和
@foreach (var item1 in Model){
if(num != item1.level){
num = item1.level;
<ul class="@Html.DisplayFor(modelItem => item1.circleLevel)">
@foreach (var item in Model){
if(item1.level == item.level){
<li>
<a class="text" style="background-color:
@Html.DisplayFor(modelItem => item.IsExest)"
href="@Url.Action("Details",
"Tree", new { id = item.User_ID
})">@Html.DisplayFor(modelItem => item.Name)</a>
</li>
}
}
<li>
<div class="text" data-toggle="tooltip" data-placement="left"
title="add family member">@Html.ActionLink("+", "Create")</div>
</li>
<ul class="circle5"></ul>
}
}
</ul>
答案 0 :(得分:0)
您可以在forloop外创建ul元素,然后将li
附加到ul
元素。
这样的事情: -
var createUlElem = $('<ul class="ulClass"></ul>');
var liElem='';
$.each (items,function(indx,item1) {
liElem +='<li><a class="text">item1.name</a></li>';
})
$(createUlElem).append($(liElem));