如何在制表符中显示嵌套列表数据

如何解决如何在制表符中显示嵌套列表数据

我的屏幕上有一个搜索和列表面板。对于列表页面,我正在使用制表符,因为我想显示嵌套数据。

js文件代码

function onCheckClick() {
var url = "/SomeController/SomeAction/";
$.ajax({
    url: url,type: "Post",success: function (result) {
        var table = new Tabulator("#exampleTable",{
            dataTree: true,data: result.data.GroupList,dataTreeStartExpanded: true,dataTreeElementColumn: "GroupName",dataTreeChildField: "childRows",columns: [
                { title: "Group Name",field: "GroupName",width: 200,responsive: 0 },{ title: "%range",field: "Range",width: 150 },{ title: "Count Nutrition",field: "FoodCount",{ title: "Combined",field: "CombinedCount",hozAlign: "center",],});
    },error: function (reponse) {
    }
});
}

响应类文件具有如下嵌套的数据: 主班组列表:

public class GroupListviewmodel
{
    public List<GroupDetailEntityviewmodel> GroupList { get; set; }
    public GroupListviewmodel()
    {
        GroupList = new List<GroupDetailEntityviewmodel>();
    }
}

嵌套类:

public class GroupDetailEntityviewmodel
{ 
    public int GroupID { get; set; }
    public string GroupName { get; set; }

    public List<FoodDetailviewmodel> _children { get; set; }

    public GroupDetailEntityviewmodel()
    {
        _children = new List<FoodDetailviewmodel>();
    }
}

嵌套类FoodDetailviewmodel:

public class FoodDetailviewmodel 
{
    
    public int ID { get; set; }

    public string Range { get; set; }
    
    public int FoodCount { get; set; } 

    public int CombinedCount { get; set; }
}

我希望我的表显示如下数据:

enter image description here

但是这没有发生。仅呈现组名,隐藏数据。 我指的是制表符链接,此后为嵌套列表使用了_children命名约定=> Tabulator example

有人可以帮忙吗? 谢谢。

解决方法

您遇到的问题是因为您要将列表传递给制表符而不是数组。

尽管List对象在技术上是可诱人的,但它们与制表符所需的数组不同。

这显示了数据必须呈现给制表器的结构,以便其起作用。您会注意到childRows属性已为其分配了一个数组:

var tableDataNested = [
    {name:"Oli Bob",location:"United Kingdom",gender:"male",col:"red",dob:"14/04/1984",childRows:[
        {name:"Mary May",location:"Germany",gender:"female",col:"blue",dob:"14/05/1982"},{name:"Christine Lobowski",location:"France",col:"green",dob:"22/05/1982"},{name:"Brendon Philips",location:"USA",col:"orange",dob:"01/08/1980",childRows:[
            {name:"Margret Marmajuke",location:"Canada",col:"yellow",dob:"31/01/1999"},{name:"Frank Harbours",location:"Russia",dob:"12/05/1966"},]},{name:"Jamie Newhart",location:"India",dob:"14/05/1985"},{name:"Gemma Jane",location:"China",dob:"22/05/1982",childRows:[
        {name:"Emily Sykes",location:"South Korea",col:"maroon",dob:"11/11/1970"},{name:"James Newman",location:"Japan",dob:"22/03/1998"},];

按原样存储数据没有错,特别是如果您需要其他功能来在应用程序的其余部分中对其进行操作时。但是,为了使制表器正确理解它,您需要先将其映射为上述格式,然后再将其传递给制表器。

有关如何在Tabulator中使用嵌套数据的详细信息,请参见Data Tree Documentation

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?