没有数据绑定的情况下如何使用sapui5 SmartField?

时间:2019-04-12 01:05:45

标签: sapui5

我似乎无法弄清楚如何在没有数据绑定的情况下使SmartField正常工作。问题是没有数据绑定时,输入的值将被清除。

我已经坚持了好几天了;我尝试更改元数据中的'sap:'标签,但无济于事。如果我将字段更改为SmartMultiInput,则效果很好; SAPUI5的系列教程中还有一个特定示例,用于不带数据绑定的SmartMultiInput-但SmartField上没有。

myView.view.xml:

<mvc:View
    controllerName="sap.ui.demo.smartControls.SmartField"
    xmlns="sap.m"
    xmlns:form="sap.ui.layout.form"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:smartField="sap.ui.comp.smartfield">
    <form:SimpleForm
        minWidth="1024"
        maxContainerCols="2"
        editable="true"
        layout="ResponsiveGridLayout"
        labelSpanL="3"
        labelSpanM="3"
        emptySpanL="4"
        emptySpanM="4"
        columnsL="1"
        columnsM="1"
        class="editableForm">
        <form:content>
            <smartField:SmartLabel labelFor="idProduct"/>
            <smartField:SmartField value="{ProductId}"  entitySet="Products" id="idProduct"/>
        </form:content>
    </form:SimpleForm>
</mvc:View>

myController.controller.js

sap.ui.define([
    "sap/ui/core/mvc/Controller"
], function(Controller) {
    "use strict";

    return Controller.extend("sap.ui.demo.smartControls.SmartField", {
        onInit: function() {
                        //SmartField will work if the following code is uncommented
            //this.getView().bindElement("/Products('4711')");
        }
    });

});

metadata.xml

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0"
    xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
    xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
    xmlns:sap="http://www.sap.com/Protocols/SAPData">
    <edmx:DataServices m:DataServiceVersion="2.0">
        <Schema Namespace="com.sap.wt02" 
            sap:schema-version="1" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
            <EntityType Name="Product">
                <Key>
                    <PropertyRef Name="ProductId" />
                </Key>
                <Property Name="ProductId" Type="Edm.String" />
                <Property Name="Price" Type="Edm.String" 
                    sap:unit="CurrencyCode" MaxLength="3" sap:label="Price"
                    sap:updatable="true" />
                <Property Name="CurrencyCode" Type="Edm.String" 
                    MaxLength="3" sap:label="Currency" sap:semantics="currency-code"
                    sap:updatable="true" />
            </EntityType>
            <EntityContainer m:IsDefaultEntityContainer="true"
                sap:supported-formats="atom json">
                <EntitySet Name="Products" EntityType="com.sap.wt02.Product" sap:creatable="true" sap:updatable="true" sap:addressable="true" sap:deletable="true" />
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>    

Products.json

[
  {
    "ProductId": "4711",
    "Price": 856.49,
    "CurrencyCode": "EUR"
  }
]

0 个答案:

没有答案
相关问题