admin管理员组

文章数量:1122832

I'm using SAPUI5 with an OData V4 Model with ASP.NET as a backend.

I have Reservations which have a stauses. I need a functionality that the user can change the Status of a Reservation. All statuses are predefined and already exits on the database. I just need to change the from the Reservation to the Status and I want to use the ODataModel for that, preferably the Status being selectable from a sap.m.Select.

Is this possible? Or do I have to use a change-Event on the Select and make a PUT request by hand?

My (reduced) OData metadata:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="4.0" xmlns:edmx=";>
  <edmx:DataServices>
    <Schema Namespace="Namespace"
      xmlns=";>
      <EntityType Name="Reservation">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <NavigationProperty Name="Status" Type="Namespace.ReservationStatus" />
        <NavigationProperty Name="Resources" Type="Collection(Namespace.Resource)" />
      </EntityType>
      <EntityType Name="ReservationStatus">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="120" />
        <Property Name="Id" Type="Edm.Int32" Nullable="false" />
      </EntityType>
      <EntityType Name="Resource">
        <Key>
          <PropertyRef Name="Id" />
        </Key>
        <Property Name="Name" Type="Edm.String" MaxLength="120" />
        <NavigationProperty Name="Reservations" Type="Collection(Namespace.Reservation)" />
      </EntityType>
    </Schema>
    <Schema Namespace="Default" xmlns=";>
      <EntityContainer Name="Container">
        <EntitySet Name="Reservations" EntityType="Namespace.Reservation">
          <NavigationPropertyBinding Path="Resources" Target="Resources" />
          <NavigationPropertyBinding Path="Status" Target="ReservationStatuses" />
        </EntitySet>
        <EntitySet Name="ReservationStatuses" EntityType="Namespace.ReservationStatus" />
        <EntitySet Name="Resources" EntityType="Namespace.Resource">
          <NavigationPropertyBinding Path="Reservations" Target="Reservations" />
        </EntitySet>
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

Frontend implementations

Create Reservation through ODataModel and open Dialog

onCreateReservationButtonPress() {
    const oAppointment = this.byId("idSinglePlanningCalendar").getBinding("appointments").create();

    oAppointment.created().then(() => {
        // Dialog is created and stored in this.dialog_reservation
        this.getView().addDependent(this.dialog_reservation);
        this.dialog_reservation.bindElement({
            path: oAppointment.getPath(),
            parameters: {
                '$expand': 'Status'
            }
        });
        this.dialog_reservation.open();
    });
}

Dialog implementation

<c:FragmentDefinition
    xmlns="sap.m"
    xmlns:c="sap.ui.core"
    xmlns:f="sap.ui.layout.form"
>
    <f:SimpleForm editable="true">
        <Label text="Name" />
        <Input
            id="idNameInput"
            value="{Name}"
            maxLength="120"
        />
        <Label text="Status" />
        <Select items="{/ReservationStatuses}">
            <items>
                <c:Item
                    text="{Name}"
                    key="{Id}"
                />
            </items>
        </Select>
    </f:SimpleForm>
</c:FragmentDefinition>

本文标签: Update NavigationProperty in SAPUI5 with OData V4 Model (with ASPNET backend)Stack Overflow