SAPUI5 - 根据产品获取供应商列表

时间:2018-05-28 10:12:17

标签: sapui5

我尝试使用下面的代码,但它提供了所有供应商的列表

Here is what i have done

<ObjectPageSection title="Suppliers">
            <subSections>
                <ObjectPageSubSection>
                    <blocks>
                        <m:Table id="suppliersTable" items="{path : 'products>/Products' , parameters:{expand : 'Supplier'} }">
                            <m:columns>
                                <m:Column/>
                            </m:columns>
                            <m:items>
                                <m:ColumnListItem >
                                    <m:cells>
                                        <m:ObjectIdentifier text="{products>Supplier/Name}"/>
                                    </m:cells>
                                </m:ColumnListItem>
                            </m:items>
                        </m:Table>
                    </blocks>
                </ObjectPageSubSection>
            </subSections>
        </ObjectPageSection>

我使用了Northwind OData service -

我只想要那些与产品相关的供应商 如下所示:

Supplier1Supplier2

任何人都可以帮助我。

2 个答案:

答案 0 :(得分:0)

我在manifest.json

中设置了导航
    "routing": {
        "config": {
            "routerClass": "sap.m.routing.Router",
            "viewType": "XML",
            "viewPath": "Product.view",
            "controlId": "app",
            "controlAggregation": "pages"
        },
        "routes": [{
            "pattern": "",
            "name": "productList",
            "target": "productList"
        }, {
            "pattern": "detail/{productsData}/Supplier",
            "name": "detail",
            "target": "detail"
        }],
        "targets": {
            "productList": {
                "viewName": "ProductList"
            },
            "detail": {
                "viewName": "Detail"
            }
        }
    }

我正在从ProductList页面导航到Details页面 ProductList Page

答案 1 :(得分:0)

首先将元素绑定到控制器上的视图(将其放在handleRouteMatched方法上):

        var self = this;
        var argsId = oEvent.getParameters().data.Id;
        var view = self.getView();
        var yourTable = view.byId("suppliersTable");
        yourTable.bindElement({
            path: "products>/Products('" + argsId + "')",
            parameters: { expand: "Supplier" },
            events: {
                dataRequested: function () {
                    self.getView().setBusy(true);
                    //some error handling logic you might want
                },
                dataReceived: function () {
                    self.getView().setBusy(false);
                }
            }
        });

这将使表格上的所有绑定相对于触发导航的产品。您的视图代码将如下所示:

<ObjectPageSection title="Suppliers">
            <subSections>
                <ObjectPageSubSection>
                    <blocks>
                        <m:Table id="suppliersTable">
                            <m:columns>
                                <m:Column/>
                            </m:columns>
                            <m:items>
                                <m:ColumnListItem >
                                    <m:cells>
                                        <m:ObjectIdentifier text="{products>Supplier/Name}"/>
                                    </m:cells>
                                </m:ColumnListItem>
                            </m:items>
                        </m:Table>
                    </blocks>
                </ObjectPageSubSection>
            </subSections>
        </ObjectPageSection>