如何在xml视图上显示另一个OData对象内部的OData对象? [sapui]

时间:2017-05-16 18:02:45

标签: odata sapui5

我有这个OData模型:

<EntityType Name="Request">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="AirTicketBuyer" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="AirTicketBuyerEmail" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="BusTicketBuyer" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="BusTicketBuyerEmail" Type="Edm.String" Nullable="true" MaxLength="50"/>
<Property Name="CostCenter" Type="Edm.Int32" Nullable="false"/>
<Property Name="Created" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Currency" Type="Edm.Int32" Nullable="false"/>
<Property Name="Department" Type="Edm.Int32" Nullable="false"/>
<Property Name="DepartureDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="DepartureRoute" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="DepartureTransportationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="Destination" Type="Edm.String" Nullable="false" MaxLength="128"/>
<Property Name="DestinationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="ExpirationDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Id" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdApplicant" Type="Edm.Int32" Nullable="true"/>
<Property Name="IdCompany" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdUser" Type="Edm.Int32" Nullable="false"/>
<Property Name="Reason" Type="Edm.String" Nullable="false" MaxLength="200"/>
<Property Name="RequestCode" Type="Edm.String" Nullable="false" MaxLength="15"/>
<Property Name="RequestFatherId" Type="Edm.Int32" Nullable="true"/>
<Property Name="RequestStatus" Type="Edm.Int32" Nullable="false"/>
<Property Name="RequestType" Type="Edm.Int32" Nullable="false"/>
<Property Name="ReturnDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="ReturnRoute" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="ReturnTransportationType" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="SapCodeApplicant" Type="Edm.String" Nullable="true" MaxLength="6"/>
<Property Name="SapCodeUser" Type="Edm.String" Nullable="true" MaxLength="6"/>
<Property Name="StartFlowDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="TipoReq" Type="Edm.String" Nullable="true" MaxLength="2"/>
<Property Name="TotalAdvance" Type="Edm.Decimal" Nullable="false" Precision="12" Scale="2"/>
<NavigationProperty Name="ApprovalsRequestDetails" Relationship="rva-persistence.ApprovalsRequest_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ApprovalsRequest"/>
<NavigationProperty Name="CostCenterDetails" Relationship="rva-persistence.Request_CostCenter_Many_ZeroToOne0" FromRole="Request" ToRole="CostCenter"/>
<NavigationProperty Name="CurrencyDetails" Relationship="rva-persistence.Currency_Request_One_Many0" FromRole="Request" ToRole="Currency"/>
<NavigationProperty Name="DepartmentDetails" Relationship="rva-persistence.Department_Request_One_Many0" FromRole="Request" ToRole="Department"/>
<NavigationProperty Name="ExpenseAdvanceDetails" Relationship="rva-persistence.ExpenseAdvance_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ExpenseAdvance"/>
<NavigationProperty Name="CompanyDetails" Relationship="rva-persistence.Company_Request_One_Many0" FromRole="Request" ToRole="Company"/>
<NavigationProperty Name="UsersDetails" Relationship="rva-persistence.Users_Request_One_Many0" FromRole="Request" ToRole="Users"/>
<NavigationProperty Name="PassengerDetails" Relationship="rva-persistence.Passenger_Request_Many_ZeroToOne0" FromRole="Request" ToRole="Passenger"/>
<NavigationProperty Name="ReportDocumentDetails" Relationship="rva-persistence.ReportDocument_Request_Many_ZeroToOne0" FromRole="Request" ToRole="ReportDocument"/>
<NavigationProperty Name="RequestStatusDetails" Relationship="rva-persistence.Request_RequestStatus_Many_ZeroToOne0" FromRole="Request" ToRole="RequestStatus"/>
<NavigationProperty Name="RequestTypeDetails" Relationship="rva-persistence.RequestType_Request_One_Many0" FromRole="Request" ToRole="RequestType"/>
</EntityType>

如您所见,tis对象内部有另一个OData对象(用户):

<EntityType Name="Users">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Area" Type="Edm.String" Nullable="true" MaxLength="10"/>
<Property Name="DocumentType" Type="Edm.Int32" Nullable="true"/>
<Property Name="Email" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="ErpId" Type="Edm.String" Nullable="true" MaxLength="20"/>
<Property Name="ExpirationDate" Type="Edm.DateTime" Nullable="true"/>
<Property Name="Id" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdCompany" Type="Edm.Int32" Nullable="false"/>
<Property Name="IdNumber" Type="Edm.String" Nullable="true" MaxLength="30"/>
<Property Name="JoinDate" Type="Edm.DateTime" Nullable="false"/>
<Property Name="Password" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="Status" Type="Edm.String" Nullable="false" MaxLength="1"/>
<Property Name="UserAlias" Type="Edm.String" Nullable="false" MaxLength="60"/>
<Property Name="UserName" Type="Edm.String" Nullable="false" MaxLength="100"/>
//Navigations
</EntityType>

我有一个主 - 详细信息页面。我有一个主对象列表(请求类型)和详细页面,我可以看到它们的属性。我可以看到所有的属性,但除了来自&#34;用户&#34;对象

首先,我创建了一个JSONModel对象,其中包含&#34; Request&#34;的对象。类型:

var jsonModelObject = new JSONModel(requestObject, false);

this.setModel(jsonModelObject, "detailView");

在我的详细信息页面中,我无法看到&#34;用户&#34;对象

这有效:

<Input fieldGroupIds="datos_suscripcion" value="{detailView>/TipoReq}"
                       placeholder="Código..." 
                       id="inTipoReq"/>

这不起作用:

第一路:

<Input fieldGroupIds="datos_suscripcion" value="{detailView>/UsersDetails>/UserName}"
                       placeholder="Usuario..." 
                       id="inUsuario"/>

第二路:

<Input fieldGroupIds="datos_suscripcion" value="{detailView/UsersDetails>/UserName}"
                       placeholder="Usuario..." 
                       id="inUsuario"/>

感谢您的回复:)。

更新1

@Alan,我正在尝试这种方式:

首先:

<VBox items="{path : 'detailView>/',  parameters: {expand: 'UsersDetails'} }">
                <Input fieldGroupIds="datos_suscripcion" value="{UserName}"
                    placeholder="Usuario..." 
                    id="inUsuario"/>
            </VBox>

第二:

<VBox items="{path : 'detailView>/',  parameters: {expand: 'UsersDetails'} }">
                    <Input fieldGroupIds="datos_suscripcion" value="{detailView>/UsersDetails/UserName}"
                        placeholder="Usuario..." 
                        id="inUsuario"/>
                </VBox>

它们都不起作用......当我选择主对象时,好奇,艾伦的方式以及我的方式输入在我的页面中出现多次。

我的页面类似于Master-Deail示例。我的页面包含一个主对象列表。当我选择主对象时,他的属性显示在详细信息页面上。我使用press事件在详细信息页面上显示属性。为此,请求不会被触发... Here您可以通过更多详细信息来举例说明。

1 个答案:

答案 0 :(得分:0)

无法直接访问导航属性。您可以执行以下操作 -

<VBox items="{path : 'detailView>/',  parameters: {expand: 'UsersDetails'} }">
   <Label text="{destination}"></Label>
   <VBox items={UsersDetails}>
      <Label text="{UserName}"></Label>
   </VBox>
</VBox>

我认为问题在于,当您运行展开时,结果将如下所示 -

  {"AirTicketBuyer":"xxxx",
   ..,
   "TotalAdvance";"xxxx",
   "UserDetails": {
      "results":[{
           "UserName": "this is an user name", 
           ...
       }]
   }}

因此,您需要两个模板来运行绑定。如果它不起作用,请尝试在每次绑定之前添加detailView&gt; /。