与 JSONModel 相比,输入验证不适用于 v2.ODataModel

2024-05-19

在当前的项目中,我有一个简单的形式 https://openui5.hana.ondemand.com/#/api/sap.ui.layout.form.SimpleForm/在一个视图上。在此视图上绑定 JSONModel,validateValue函数在我的输入字段上运行良好。输入字段的约束定义如下:

<Input value="{
  path: '/carrId',
  type: 'sap.ui.model.type.String',
  constraints: {
    // ... 
  }
}"/>

将模型更改为ODataModel不触发validateValue如果约束不匹配,则该字段不会标记为红色。

该视图在消息管理器中注册。

我是否必须通过实施来实施验证change事件或错误在哪里?


  1. Replace sap.ui.model.type.String with the type corresponding to the EDM type of your carrId. E.g. with sap.ui.model.odata.type.String https://openui5.hana.ondemand.com/#/api/sap.ui.model.odata.type.String if it has the Type="Edm.String" in metadata. Note that the constraints settings are also different.

  2. 为了真正允许将用户输入从 UI 传输回模型,从而触发parseValue and validateValue自动地,绑定模式需要是TwoWay(默认绑定方式为v2.ODataModel is OneWay*).

    • Open manifest.json

    • Set /sap.ui5/models/<modelName>/settings/defaultBindingMode to "TwoWay":

      {
        "dataSource": "MyV2ODataSource",
        "settings": {
          "defaultBindingMode": "TwoWay",
          "preliminaryContext": true
        },
        "preload": true
      }

* See 绑定方式:一次性绑定、单向绑定、双向绑定 https://openui5nightly.hana.ondemand.com/topic/68b9644a253741e8a4b9e4279a35c247#section_BindingModes

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

与 JSONModel 相比,输入验证不适用于 v2.ODataModel 的相关文章

随机推荐