前端 在ul李定义id为
<div class="tabcon">
<div class="cs-mbss">
<input class="dm-input1" style="width:140px;" id="q" placeholder="输入关键词" type="text" />
<a class="ss-btn" onclick="getTemplates()"><i class="fa fa-search"></i> 搜索</a>
</div>
<ul id="tttree">1</ul>
</div>
js
function getTemplates(){
getAsyncAjaxDataPost({q:$("#q").val(),type:1}, "/PACS/getBCResultTemplates", function (data) {
$("#tttree").tree({
data: data,
idField: 'id',
treeField: 'text',
onClick: function (node) {
}, onDblClick: function (node) {
console.log(node)
if (node.Bcresult != null && node.Bcresult != '') {
$("#ImagingConclusion").val(node.Bcresult);
}
if (node.Bcview != null && node.Bcview != '') {
$("#ImageContent").val(node.Bcview);
}
}
})
});
}
后端
public async Task<object> getBCResultTemplates(string q, int id = 0, int Type = 0)
{
if (string.IsNullOrEmpty(q))
{
var mm = await _dbContext.HisMedicaTemplates.Where(x=>x.Type== Type).OrderBy(c => c.ParentId).Select(c => new PASCSResult { id = c.Id, parentId = c.ParentId.HasValue ? c.ParentId.Value : 0, text = c.ModelName, state = "closed", Bcresult = c.Bcresult, Bcview = c.Bcview, Remark = c.Remark }).ToListAsync();
var mm1 = mm.Where(c => c.parentId == 0);
List<PASCSResult> results0 = new List<PASCSResult>();
foreach (var item in mm1)
{
setPACSResult(mm, item.id, item);
results0.Add(item);
}
}
public void setPACSResult(List<PASCSResult> result, int parentId, PASCSResult result1)
{
var mm2 = result.Where(c => c.parentId == parentId);
foreach (var item in mm2)
{
setPACSResult(result, item.id, item);
if (result1.children == null)
{
result1.children = new List<PASCSResult>();
}
result1.children.Add(item);
}
}
public class PASCSResult
{
public int id { get; set; }
public int parentId { get; set; }
public string text { get; set; }
public string state { get; set; } = "closed";
public string Bcresult { get; set; }
public string Bcview { get; set; }
public string Remark { get; set; }
public List<PASCSResult> children { get; set; }
}
表结构
实现效果