如何在sapui5中实现TreeTable

时间:2014-08-08 10:05:01

标签: sap sapui5

我有这样的模型

[ {"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"属性。

2 个答案:

答案 0 :(得分:4)

TreeTable使用的sap.ui.model.ClientTreeBinding与JSONModel或XMLModel支持参数arrayNames。 此参数需要一个模型属性名称数组,它将创建一个子级别(如果包含一个对象)。

所以在你的例子中你应该使用这样的东西:

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

或在XMLView中:

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

除了one example之外,在文档中找不到这个内容。您可以找到示例in the openui5 github的来源。

答案 1 :(得分:0)

试一试

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");