代码之家  ›  专栏  ›  技术社区  ›  Ajay

表格标题在UI5应用程序中不可见

  •  0
  • Ajay  · 技术社区  · 6 年前

    我已经创建了一个表,但没有显示标题。在我的组件中,我正在读取OData实体并将其存储在JSON模型中。然后使用此JSON模型绑定标题列文本。

    我附上了表格输出图像以供参考:

    enter image description here

    标题视图。xml:

    <mvc:View controllerName="NPAWRMA.controller.header" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
        displayBlock="true" xmlns="sap.m" xmlns:l="sap.ui.layout">
        <App id="idAppControl">
            <pages>
                <Page title="NPAW RMA Report">
                    <content>
                        <l:VerticalLayout>
                            <Table id="table" growing="true" items="{odata>/RmaPercRevColSet}">
                                <columns>
                                    <Column>
                                        <Text text="CBU" id="CbuShortNameColumnTitle"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label01}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label02}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label03}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label04}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label05}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label06}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label07}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label08}"/>
                                    </Column>
                                </columns>
                                <items>
                                    <ColumnListItem type="Active" press="onPress">
                                        <cells>
                                            <Text text="{odata>CbuShortName}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc01', formatter: '.formatter.numberUnit' }"  state="{State01}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc02', formatter: '.formatter.numberUnit' }"  state="{State02}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc03', formatter: '.formatter.numberUnit' }"  state="{State03}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc04', formatter: '.formatter.numberUnit' }"  state="{State04}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc05', formatter: '.formatter.numberUnit' }"  state="{State05}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc06', formatter: '.formatter.numberUnit' }"  state="{State06}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc07', formatter: '.formatter.numberUnit' }"  state="{State07}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc08', formatter: '.formatter.numberUnit' }"  state="{State08}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc09', formatter: '.formatter.numberUnit' }"  state="{State09}"/>
                                        </cells>
                                    </ColumnListItem>
                                </items>
                            </Table>
                            <Table id="table1" growing="true" items="{odata>/RmaPercRevColSet}">
                                <columns>
                                    <Column>
                                        <Text text="CBU" id="CbuShortNameColumnTitle1"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label01}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label02}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label03}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label04}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label05}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label06}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label07}"/>
                                    </Column>
                                    <Column>
                                        <Text text="{Labels>/Labels1/Label08}"/>
                                    </Column>
                                </columns>
                                <items>
                                    <ColumnListItem type="Active" press="onPress">
                                        <cells>
                                            <Text text="{odata>CbuShortName}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc01', formatter: '.formatter.numberUnit' }" unit="%" state="{State01}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc02', formatter: '.formatter.numberUnit' }" unit="%" state="{State02}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc03', formatter: '.formatter.numberUnit' }" unit="%" state="{State03}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc04', formatter: '.formatter.numberUnit' }" unit="%" state="{State04}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc05', formatter: '.formatter.numberUnit' }" unit="%" state="{State05}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc06', formatter: '.formatter.numberUnit' }" unit="%" state="{State06}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc07', formatter: '.formatter.numberUnit' }" unit="%" state="{State07}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc08', formatter: '.formatter.numberUnit' }" unit="%" state="{State08}"/>
                                            <ObjectNumber number="{ path: 'odata>NpiPerc09', formatter: '.formatter.numberUnit' }" unit="%" state="{State09}"/>
                                        </cells>
                                    </ColumnListItem>
                                </items>
                            </Table>
                        </l:VerticalLayout>
                    </content>
                </Page>
            </pages>
        </App>
    </mvc:View>
    

    组成部分js公司:

    sap.ui.define([
    	"sap/ui/core/UIComponent",
    	"sap/ui/Device",
    	"NPAWRMA/model/models"
    ], function(UIComponent, Device, models) {
    	"use strict";
    
    	return UIComponent.extend("NPAWRMA.Component", {
    
    		metadata: {
    			manifest: "json"
    		},
    
    		/**
    		 * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
    		 * @public
    		 * @override
    		 */
    		init: function() {
    			//"Access-Control-Allow-Origin: *.local.com";
    			//"Access-Control-Allow-Headers: X-KEY";
    			UIComponent.prototype.init.apply(this, arguments);
    				debugger;
    			var sModel = this.getModel("odata");
    			sModel.setSizeLimit(999);
    			var oJson1 = new sap.ui.model.json.JSONModel();
    			sModel.read("/Labels1Set('0')", {
    				success: function(oss) {
    					oJson1.setData({
    						Label: oss
    					});
    				},
    				error: function(oss) {}
    			});
    			this.setModel(oJson1, "Labels");
    			            
     			// enable routing
    			this.getRouter().initialize();
    			// set the device model
    			this.setModel(models.createDeviceModel(), "device");
    		}
    	});
    });
    1 回复  |  直到 6 年前
        1
  •  1
  •   Serban Petrescu    6 年前

    在屏幕截图中,实际显示的是表格标题。正确呈现第一列标题(静态绑定)。

    annotated table screenshot

    因此,问题似乎在于绑定路径或模型内容本身。 我不完全确定你在 sModel.read("/Labels1Set('0')", ...) 成功回调,因为它完全取决于您如何定义OData模型。你应该检查一下 Label01 Label08 属性。

    我能发现的另一件事是,您实际上是在 /Label 绑定路径,但您正在使用 /Labels1/LabelXX 绑定路径(即路径以 Labels1 而不仅仅是 Label )。若要解决此问题,应调整读取调用的成功回调:

    success: function(oss) {
        oJson1.setData({
            Labels1: oss
        });
    }
    

    或者,更具可读性的可能是 oJson1.setData(oss) 然后只需移除 /Labels1 来自绑定路径的前缀。