首页 > 解决方案 > Dynamic Table binding

问题描述

Please suggest. Table binding does not work. Model Data and may change:

​{ "TestCloudEnvRO": [ { "pipelineName": "RP1", "cycles": [ "cy1", "cycle1", "RP1cy2", "cyc2", "crCycle" ] }, { "pipelineName": "RP2", "cycles": [ "BP1-c2", "bp2-cy" ] }, { "pipelineName": "RPlocal", "cycles": [ "cyclelocal" ] }, { "pipelineName": "rp1234", "cycles": [ "cyclert" ] }, { "pipelineName": "RPTEST", "cycles": [ "BPTEST1" ] }, { "pipelineName": "rp123", "cycles": [ "cytr" ] } ] }

View

<Table id="idtrlAllPipelines" alternateRowColors="true">
                                            
                    <columns>
                        <Column demandPopin="true" minScreenWidth="Tablet">
                            <Text text="Release Pipeline Cycles"/>
                        </Column>
</columns>

Controller

var oTemplate = new sap.m.ColumnListItem({ cells: [ new sap.m.Text({ text: "{getHist>pipelineName}" }) ] }); this.byId("idtrlAllPipelines").setModel(oModelEnv, "getHist");

this.byId("idtrlAllPipelines").bindAggregation("items", { path: "getHist>/TestCloudEnvRO", template: oTemplate, templateShareable: true } );

It does not load any items in the table. But this works at View. I have to replace this with /TestCloudEnvRO with selected key of Icon tab filter, so the above should work. Please suggest.

<Table items="{path: 'getHist>/TestCloudEnvRO'}" id="idtrlAllPipelines" alternateRowColors="true">

标签: sapui5

解决方案


对于您建议的绑定,您的数据集可能需要稍作修改才能达到要求。PFB 代码。

控制器

    loadDataSet: function () {
        var oMasterModel = this.getView().getModel("oMasterModel");
        var oDataSet = [{
            "IconTabName": "Env1",
            "Table": [{
                "name": "Person1",
                "runs": ["10", "20"]
            }, {
                "name": "Person2",
                "runs": ["0", "2"]
            }]
        }, {
            "IconTabName": "Env2",
            "Table": [{
                "name": "Person3",
                "runs": ["5", "25"]
            }, {
                "name": "Person4",
                "runs": ["20", "12"]
            }]
        }];
        oMasterModel.setData({
            allFilters: oDataSet
        });
        oMasterModel.refresh(true);
    }

看法

<IconTabBar items="{oMasterModel>/allFilters}">
                    <items>
                        <IconTabFilter text="{oMasterModel>IconTabName}">
                            <Table items="{oMasterModel>Table}">
                                <columns>
                                    <Column>
                                        <Label text="Name"/>
                                    </Column>
                                    <Column >
                                        <Label text="Runs"/>
                                    </Column>
                                </columns>
                                <items>
                                    <ColumnListItem>
                                        <cells>
                                            <Text text="{oMasterModel>name}"/>
                                            <Select items="{oMasterModel>runs}">
                                                <core:Item text="{oMasterModel>}"/>
                                            </Select>
                                        </cells>
                                    </ColumnListItem>
                                </items>
                            </Table>
                        </IconTabFilter>
                    </items>
                </IconTabBar>

推荐阅读