SimpleForm上的SAPUI5数据绑定 [英] SAPUI5 Data Binding on SimpleForm

查看:233
本文介绍了SimpleForm上的SAPUI5数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用简单的表单尝试绑定数据时遇到问题。我正在使用一个模拟服务器并成功地将数据绑定到列表/表中

I am having issues trying to bind data on a simple form. I am using a mock server and have successfully bind data to a list/table

我的manifest.json看起来像这样

My manifest.json looks like this

"mock": {
    "dataSource": "mainService"
}

我的mockdata(UserDetailsS​​et.json)看起来像这样

My mockdata(UserDetailsSet.json) looks like this

[{
    "ID_PassNum": "cu001",
    "Title": "Mr",
    "Name": "Don",
    "Surname": "Ownery",
    "ResType": "SA",
    "Country": "South Africa"
}]

我的SimpleForm字段看起来像这样

My SimpleForm fields looks like this

<Label text="Name" />
<Input value="{mock>/UserDetailsSet/0/Name}" />
<Label text="Surname" />
<Input value="{mock>/UserDetailsSet/0/Surname}"/>

我缺少什么?

推荐答案

您似乎正在使用 ODataModel 。在集合/聚合中的ODataModels绑定并不像JSONModel那么容易。您不能使用 collection / index / property 语法访问/绑定属性。

You seem to be using an ODataModel. In ODataModels binding against collections/aggregations is not as easy as it is with a JSONModel. You can't access/bind properties with the collection/index/property syntax.

如何使用ODataModels存储数据

如果您加载像您的 UserDetailSet 的实体,则存储在您的ODataModel中的数据就像看起来像这样:

If you load an entity set like your UserDetailSet the data stored in you ODataModel like look somewhat like this:

{
  UserDetailSet('00001'): { ... },
  UserDetailSet('00002'): { ... },
  UserDetailSet('00003'): { ... },
  UserDetailSet('00004'): { ... }
}

而00001等等是实体密钥。如果您在 UserDetailSet 上创建聚合绑定,则ODataListBinding将处理将上述数据转换为每个项目的上下文。

Whereas '00001' and so forth is the entities key. If you create an aggregation binding on UserDetailSet the ODataListBinding will handle translating the above data into a context per item.

ODataModel上的属性绑定

您的绑定必须如下所示:

Your binding would have to look like this:

<Label text="Name" />
<Input value="{mock>/UserDetailSet('00001')/Name}" />
<Label text="Surname" />
<Input value="{mock>/UserDetailSet('00001')/Surname}"/>

ODataModel上的动态属性绑定

或者 - 要有点动态 - 这样绑定(注意:绑定是相对的,没有领导 / ):

Or - to be a little more dynamic - bind like this (Note: the bindings are relative now, no leading /):

<SimpleForm id="MyForm">
  <Label text="Name" />
  <Input value="{mock>Name}" />
  <Label text="Surname" />
  <Input value="{mock>Surname}"/>
</SimpleForm>

,并在SimpleForm本身上动态使用 bindElement

and dynamically use bindElement on the SimpleForm itself:

this.getView().byId("MyForm").bindElement({
  path: "/UserDetailSet('"+ sUserID +"')",
  model: "MyOdataModelID",
  // use OData parameters here if needed
  parameters: {
    "expand": "UserAdress"
  },
  // react on binding events here
  events: {
    change: function (oEv) { },
    dataRequested: function (oEv) { },
    dataReceived: function (oEv) {}
  }
});

BR
Chris

BR Chris

这篇关于SimpleForm上的SAPUI5数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆