亲爱的UI5专家!
我正面临OData v4模型的绑定问题。我有一个简单的OData结构,其中Persons被分配给Department,请参阅metadata.xml中的摘录:
...
<EntityType Name="Person">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.Int64"/>
<Property Name="FirstName" Type="Edm.String"/>
<Property Name="LastName" Type="Edm.String"/>
<Property Name="Email" Type="Edm.String"/>
<Property Name="Mobile" Type="Edm.String"/>
<Property Name="Username" Type="Edm.String"/>
<NavigationProperty Name="Department" Type="OData.WTS.Department" Partner="Person"/>
</EntityType>
<EntityType Name="Department">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.Int64"/>
<Property Name="Name" Type="Edm.String"/>
<NavigationProperty Name="Person" Type="OData.WTS.Person" Partner="Department"/>
</EntityType>
...
现在我想构建一个UI5应用程序,让用户创建应该分配给部门的新人员(应该通过ValueHelp选择)。因此,我创建了一个列表页面,其项目绑定到模型:
<Table items="{ path: 'userService>/Persons', parameters : {$expand: 'Department'} }">
...
</Table>
部门本身受XML视图约束:
...
<form:FormElement>
<form:label>
<Label text="{i18n>User.Department}"/>
</form:label>
<form:fields>
<Input id="Department"
name="{userService>Department/Id}"
value="{userService>Department/Name}"
showValueHelp="true" valueHelpOnly="true"
valueHelpRequest="onValueHelpRequestDepartment" />
</form:fields>
</form:FormElement>
...
当用户按下&#34; New Person&#34;按钮,我通过OData v4 ListBindingContext创建一个新的瞬态模型 -
oListBindingContext
.create({
Id: null,
Username: "",
FirstName: "",
LastName: "",
Email: "",
Mobile: "",
Department: {
Id : null,
Name : null
}
}, function (oError) {
// handle error
}
);
当用户现在通过ValueHelp选择部门时,我想为其分配ID并命名新创建的人员部门ID和名称。我尝试通过Input-control的setter-functions来完成这项工作,因为属性绑定到了部门:
// this should update the model-value
var oInput = this.getView().byId("Department");
oInput.setName(sSelectedId);
oInput.setValue(oSelectedBindingContext.getProperty("Name"));
但这会导致异常:
Failed to update path /Persons/-1/Department/Name - Error: /Persons/-1/Department/Name: No key predicate known at /Persons/-1/Department
at error (http://localhost/ui5resources/sap/ui/model/odata/v4/ODataMetaModel-dbg.js?eval:1189:10)
at eval (http://localhost/ui5resources/sap/ui/model/odata/v4/ODataMetaModel-dbg.js?eval:1297:7)
at new SyncPromise (http://localhost/ui5resources/sap/ui/model/odata/v4/lib/_SyncPromise-dbg.js?eval:72:15)
at SyncPromise.then (http://localhost/ui5resources/sap/ui/model/odata/v4/lib/_SyncPromise-dbg.js?eval:151:12)
at eval (http://localhost/ui5resources/sap/ui/model/odata/v4/ODataMetaModel-dbg.js?eval:1288:47)
您是否有任何提示如何使用OData v4实现此简单方案?我在这里误解了OData v4概念吗?我正在使用OpenUI5版本1.50.6。
提前致谢:-) 的Mirco