数据在第二个视图中不可见

时间:2017-09-11 10:11:15

标签: sapui5

我面临一个问题,即数据在我的项目中不可见。

我创建了两个视图:Input.view.xmlplant.view.xml。在我的第一个视图中,我有一个按钮作为“材料详细信息”,点击该按钮后,它将移动到第二个视图。然而,它变得空白。

我的JSON文件包含所有数据,但它不在第二个视图中。

您能否说明问题是什么以及如何解决?

“输入视图”(第一视图)

<mvc:View
    controllerName="stock.controller.main"
    xmlns:l="sap.ui.layout"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:viz="sap.viz.ui5.controls"
    xmlns="sap.m">
    <App id="app">
        <l:VerticalLayout
            class="sapUiContentPadding"
            width="100%"
            height="100%">
            <Label
                text="Product"
                labelFor="productInput" />
            <Input id="productInput"
                placeholder="Enter Material ..."
                showSuggestion="true"
                showTableSuggestionValueHelp="false"
                suggestionRows="{/ProductCollection}"
                suggestionItemSelected="onSelectItem">
                <suggestionColumns>
                    <Column
                        hAlign="Begin"
                        popinDisplay="Inline"
                        demandPopin="true">
                        <Label text="Name"/>
                    </Column>
                </suggestionColumns>
                <suggestionRows>
                    <ColumnListItem>
                        <Label id="inputKey" text="{ProductId} {Name}"/>
                    </ColumnListItem>
                </suggestionRows>
            </Input>
            <Button id="onDisplay"
                text="{i18n>materialDetails}"
                press="onDisplayPlant"
                class="sapUiTinyMarginEnd" />
        </l:VerticalLayout>
    </App>
</mvc:View>

First View

plant.view.xml(第二个视图)

<mvc:View
    controllerName="stock.controller.plant"
    xmlns="sap.m"
    xmlns:viz="sap.viz.ui5.controls"
    xmlns:l="sap.ui.layout"
    xmlns:mvc="sap.ui.core.mvc">
    <MessagePage
        showNavButton="true"
        navButtonPress="onNavBack"/>
        <Table id="idProductsTable"
            inset="false"
            items="{
                path: '/ProductCollection',
                sorter: {
                    path: 'Name'
                }
            }">
            <headerToolbar>
                <Toolbar>
                    <Title text="Products" level="H2" />
                </Toolbar>
            </headerToolbar>
            <columns>
                <Column width="12em">
                    <Text text="Product" />
                </Column>
                <Column
                    minScreenWidth="Tablet"
                    demandPopin="true">
                    <Text text="Supplier" />
                </Column>
                <Column
                    minScreenWidth="Tablet"
                    demandPopin="true"
                    hAlign="End">
                    <Text text="Dimensions" />
                </Column>
                <Column
                    minScreenWidth="Tablet"
                    demandPopin="true"
                    hAlign="Center">
                    <Text text="Weight" />
                </Column>
                <Column hAlign="End">
                    <Text text="Price" />
                </Column>
            </columns>
            <items>
                <ColumnListItem>
                    <ObjectIdentifier
                        title="{Name}"
                        text="{ProductId}"/>
                    <Text text="{SupplierName}" />
                    <Text text="{Width} x {Depth} x {Height} {DimUnit}" />
                    <ObjectNumber
                        number="{WeightMeasure}"
                        unit="{WeightUnit}"
                        state="{
                            parts: [
                                {path: 'WeightMeasure'},
                                {path: 'WeightUnit'}
                            ],
                            formatter: 'stock.Formatter.weightState'
                        }" />
                    <ObjectNumber
                        number="{
                            parts: [{
                                path: 'Price'
                            }, {
                                path: 'CurrencyCode'
                            }],
                            type: 'sap.ui.model.type.Currency',
                            formatOptions: {
                                showMeasure: false
                            }
                        }"
                        unit="{CurrencyCode}" />
                </ColumnListItem>
            </items>
        </Table>
    </MessagePage>
</mvc:View>

Second View

plant.controller.js

sap.ui.define([
    "sap/ui/core/mvc/Controller",
    "jquery.sap.global",
    "stock/Formatter",
    "sap/ui/core/routing/History",
    "sap/ui/model/json/JSONModel"
], function (Controller, jQuery, Formatter, History,JSONModel) {
    "use strict";

    var TableController =  Controller.extend("stock.controller.plant", {
        onInit: function () {
            var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
            this.getView().setModel(oModel);
        },

        getRouter : function () {
            return sap.ui.core.UIComponent.getRouterFor(this);
        },

        onNavBack: function () {
            var oHistory = History.getInstance();
            var sPreviousHash = oHistory.getPreviousHash();
            if (sPreviousHash !== undefined) {
                window.history.go(-1);
            } else {
                this.getRouter().navTo("input", {}, true);
            }
        }
    });
    return TableController;
});

Component.js

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/core/mvc/XMLView",
    "sap/ui/model/json/JSONModel"
], function(UIComponent, JSONModel, XMLView) {
    "use strict";

    var Component = UIComponent.extend("stock.Component", {
        metadata: {
            manifest: "json",
            getTable: function () {
                return this._rootView.getContent()[0];
            }
        },
        publicMethods: [
            "getTable"
        ],
        dependencies: {
            libs: [
                "sap.m",
                "sap.ui.layout"
            ]
        },
        rootView: "stock.view.input",
        config: {
            sample: {
                files: [
                    "view.input.view.xml",
                    "controller.main.controller.js",
                    "Formatter.js"
                ],
                description : "In this example assisted input is provided with table-like suggestions where several columns can display more details."
            }
        },

        init : function () {
            UIComponent.prototype.init.apply(this, arguments);
            this.getRouter().initialize();
        }
    });

    Component.prototype.createContent = function () {
        this._rootView = sap.ui.xmlview({ viewName : "stock.view.plant" });
        return this._rootView;
    };

    return Component;
});

0 个答案:

没有答案