【问题标题】:Display odata time value in UI5 form input field在 UI5 表单输入字段中显示 odata 时间值
【发布时间】:2016-09-17 06:39:29
【问题描述】:

我正在尝试在 UI5 表单输入字段中显示 edm.time 类型的 odata 属性 . 查看代码

      <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay' }" width="500%" editable="false"/>

START_TIME 是实体的属性

控制器代码-

    onInit: function () {
         var model= new sap.ui.model.odata.v2.ODataModel("<xsodata url>");
         model.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);
         this.getView().setModel(model);
         var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
         oRouter.getRoute("<pattern_name>").attachMatched(this._onObjectMatched, this);

    },
    _onObjectMatched: function (oEvent) {
        var oArgs, oView;
        oArgs = oEvent.getParameter("arguments");
        oView = this.getView();
        oView.bindElement({
             path : "/" + oArgs.objPath
        });

     }

Here object path is as follows-
    /Entityname/<id of a partcular item in that entity>

当我试图在视图中显示开始时间属性时,它返回对象对象。我需要字符串格式的时间。我已经在表格中使用了格式化程序,它工作正常。但是聚合项目绑定不同,因为它是一个表格控件。我需要 UI5 表单中输入字段中的值 请帮忙

【问题讨论】:

    标签: javascript odata sapui5


    【解决方案1】:

    binding path syntax 应该是

    /EntitySet('id')    //In case of a string id
    /EntitySet(id)      //In case of a number id
    

    也不支持开头的双//。请检查是否需要"/" +

    OData Edm.Time 可以用sap.ui.model.odata.type.Time 类型格式化:

     <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time' }" width="500%" editable="false"/>
    

    您可以进一步提供format options 来自定义输出:

     <Input id="id1" placeholder="Enter value" value="{ path: 'START_TIME', mode: 'sap.ui.model.BindingMode.OneWay', type: 'sap.ui.model.odata.type.Time', formatOptions: {style: 'short'} }" width="500%" editable="false"/>
    

    类型(与格式化程序相比)支持输入和输出转换。因此它们可以在双向绑定输入中使用,无需额外编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2020-09-05
      • 1970-01-01
      • 2017-01-25
      • 2013-03-12
      • 1970-01-01
      相关资源
      最近更新 更多