js 树状图tree({})

前端 在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>&nbsp;搜索</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; }


    }

表结构
在这里插入图片描述
实现效果
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值