如何实现treetable中的sapui5(How to implement TreeTable i

2019-10-20 15:29发布

我有这样一个模型

[ {"name":"Main 1","description":"main1 Description",
         "children": [{
               "name": "SUB 1",
               "description": "SUB 1 Description",
               "children":[
                    {
                        "name": "SUB 1.1",
                        "description": "SUB 1.1 Description"
                    },
                    {
                        "name": "SUB 1.2",
                        "description": "SUB 1.2 Description"
                    }         ]
                }],
                "parent":[{"name": "parent sub"}]
            },
   {"name":"Main 2","description":"main2 Description",children:[],parent:[]},
   {"name":"Main 3","description":"main3 Description",children:[],parent:[]},
   {"name":"Main 4","description":"main4 Description",children:[],parent:[]}
 ]

我想显示namedescription属性。 在内容"children"属性应该是一个分层次的行中,我不想显示"parent"此树表的内容。 我怎么能限制"parent"从树表属性。

Answer 1:

使用的treetable中与JSONModel或XMLModel的sap.ui.model.ClientTreeBinding支持参数arrayNames 。 此参数预计,将创建一个分段(如果包含的对象)的模型属性名称的数组。

所以,在你的榜样,你应该使用这样的:

treeTable.bindRows({path: '/pathToData', parameters: { arrayNames: ['children'] }});

或xmlView中:

<TreeTable rows="{path: '/pathToData', parameters: { arrayNames: ['children'] } }" >
...
</TreeTable>

即使世界没有太大的发现,除了这个文档中一个例子 。 你可以找到示例源在openui5 github上 。



Answer 2:

试试这应该工作

var oData={
     "children":[ 
               {"name":"Main 1","description":"main1 Description", "children": [], "parent":[]},
               {"name":"Main 2","description":"main2 Description","children":[],parent:[]},
               {"name":"Main 3","description":"main3 Description","children":[],parent:[]},
               {"name":"Main 4","description":"main4 Description","children":[],parent:[]}
           ]
   };

var oTable = new sap.ui.table.TreeTable({
    columns: [
        new sap.ui.table.Column({label: "Name", template: "name"}),
        new sap.ui.table.Column({label: "Description", template: "description"})
    ],
    selectionMode: sap.ui.table.SelectionMode.Single,
    enableColumnReordering: true,
    expandFirstLevel: true,
    });

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
oTable.setModel(oModel);
oTable.bindRows("/children");


文章来源: How to implement TreeTable in sapui5
标签: sap sapui5