展开/收缩 ul

了一个展开收缩的东东,留着以后万一用到

后台递归生成的函数(这里是一个反射参数展示,支持多层级展开显示,后台反射如何多层级解析的方法有时间再补上吧)

/// <summary>
/// 递归生成html展示request属性
/// </summary>
/// <param name="listProperties">request属性集合</param>
/// <returns>html</returns>
public static string OutputRequest(List<PropertyViewModel> listProperties)
{
const string contractImg = "<img src=\"../Cake/Easyui/themes/icons/edit_remove.png\" width=\"16px\" height=\"16px\" border=\"0px\" style=\"vertical-align: middle\" />";
const string output = "<table><tbody>{0}</tbody></table>";
var html = new StringBuilder();
if (listProperties == null || listProperties.Count <= 0) return string.Empty;

foreach (var propertyOrField in listProperties)
{
var tr = new StringBuilder();
tr.AppendFormat("<tr>");
if (propertyOrField.Type.Properties != null && propertyOrField.Type.Properties.Count > 0)
tr.AppendFormat("<td class=\"onclick\">{1}&nbsp;&nbsp;{0}</td>", propertyOrField.Name, contractImg);
else
tr.AppendFormat("<td>{0}</td>", propertyOrField.Name);
tr.AppendFormat("<td>[{0}]</td>", propertyOrField.Type.Name.EscapeSequence());//特殊字符转移 用于前端html展示
tr.AppendFormat("<td>{0}</td>", propertyOrField.Summary);
tr.AppendFormat("</tr>");
html.Append(tr);
if (propertyOrField.Type.Properties != null && propertyOrField.Type.Properties.Count > 0)
html.AppendFormat("<tr class=\"expand\"><td style=\"padding-left:30px\" colspan=\"3\">{0}</td></tr>", OutputRequest(propertyOrField.Type.Properties));
}
return string.Format(output, html);
}

posted @ 2015-03-03 14:21  茂茂  阅读(366)  评论(0编辑  收藏  举报