我在一家公司實習,我必須使用SAPUI5框架在JS中進行編碼。這對我來說是全新的,這就是爲什麼我遵循http://sapui5.hana.ondemand.com的教程。但現在我有一個問題,我不能在互聯網上找到任何意見,我不能總是問我的同事幫我,他們有工作太...SAPUI5 Metadata.xml:綁定兩個實體
我必須做一個規劃與許多員工和他們的任務。我用mockserver工作具有metadata.xml文件:
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
Version="1.0">
<edmx:DataServices
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:DataServiceVersion="1.0">
<Schema xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="NorthwindModel">
<EntityType Name="Employee">
<Key>
<PropertyRef Name="EmployeeID" />
</Key>
<Property xmlns:p8="http://schemas.microsoft.com/ado/2009/02/edm/annotation"
Name="EmployeeID" Type="Edm.Int32" Nullable="false"
p8:StoreGeneratedPattern="Identity" />
<Property Name="LastName" Type="Edm.String" Nullable="false"
MaxLength="20" Unicode="true" FixedLength="false" />
<Property Name="City" Type="Edm.String" Nullable="false"/>
<Property Name="Team" Type="Edm.String" Nullable="false"/>
<NavigationProperty Name="Appointments" Relationship="NorthwindModel.FK_Employees_Appointment"
FromRole="Employees" ToRole="Appointments"/>
</EntityType>
<EntityType Name="Appointment">
<Key>
<PropertyRef Name="AppointmentID"/>
</Key>
<Property Name="AppointmentID" Type="Edm.Int32" Nullable="false"/>
<Property Name="EmployeeID" Type="Edm.Int32" Nullable="false"/>
<Property Name="start" Type="Edm.DateTime" Nullable="false"/>
<Property Name="end" Type="Edm.DateTime" Nullable="false"/>
<Property Name="title" Type="Edm.String" Nullable="false"/>
<NavigationProperty Name="Employees" Relationship="NorthwindModel.FK_Employees_Appointment"
ToRole="Employees" FromRole="Appointments"/>
</EntityType>
<Association Name="FK_Employees_Appointment">
<End Type="Employee" Role="Employees" Multiplicity="1" />
<End Type="Appointment" Role="Appointments" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Employees">
<PropertyRef Name="EmployeeID" />
</Principal>
<Principal Role="Appointments">
<PropertyRef Name="EmployeeID" />
</Principal>
</ReferentialConstraint>
</Association>
</Schema>
<Schema xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ODataWeb.Northwind.Model">
<EntityContainer
xmlns:p7="http://schemas.microsoft.com/ado/2009/02/edm/annotation"
Name="NorthwindEntities" p7:LazyLoadingEnabled="true"
m:IsDefaultEntityContainer="true">
<EntitySet Name="Employees" EntityType="NorthwindModel.Employee" />
<EntitySet Name="Appointments" EntityType="NorthwindModel.Appointment"/>
<AssociationSet Name="FK_Employees_Appointments" Association="NorthwindModel.FK_Employees_Appointment">
<End Role="Employees" EntitySet="Employees"/>
<End Role="Appointments" EntitySet="Appointments"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
(標籤爲AssociationSet和NavigationProperty,我這樣做是因爲我已經看到我使用OData服務,但我不瞭解它,我猜這將是罰款...)
現在Appointments.json文件:
[
{
"AppointmentID" : 0,
"EmployeeID" : 0,
"start":"\/Date(1466416800000)\/",
"end":"\/Date(1466424000000)\/",
"title": "test"
},{
"AppointmentID" : 1,
"EmployeeID" : 1,
"start":"\/Date(1466409600000)\/",
"end":"\/Date(1466416800000)\/",
"title": "test2"
}]
的Employees.json文件:
[
{
"EmployeeID":0,
"LastName":"APERCE",
"City":"Paris",
"Team":"Dev"
},
{
"EmployeeID":1,
"LastName":"HACHMI",
"City":"Lille",
"Team":"Dev"
},
{
"EmployeeID":2,
"LastName":"MILLET",
"City":"Paris",
"Team":"Admin"
},
{
"EmployeeID":3,
"LastName":"CORNET",
"City":"Poitiers",
"Team":"Admin"
},
{
"EmployeeID":4,
"LastName":"EVAIN",
"City":"Paris",
"Team":"R&D"
}]
(正如你所看到的,僱員是存在於兩個Appointments.json等Employees.json)
最後的Overview.view.xml文件:
<mvc:View controllerName="sap.ui.demo.wt.controller.Overview"
xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic"
xmlns:unified="sap.ui.unified"
xmlns:core="sap.ui.core" displayBlock="true">
<semantic:FullscreenPage title="{i18n>overviewPageTitle}">
<VBox>
<PlanningCalendar startDate="{path : '/Startdate'}" rows="{path : 'data>/Employees',parameters:{expand:'Appointments'}}"
appointmentSelect="handleAppointmentSelect">
<rows>
<PlanningCalendarRow title="{data>LastName}"
appointments="{path : 'data>Appointments',templateShareable:true}">
<appointments>
<unified:CalendarAppointment
startDate="{data>start}"
endDate="{data>end}"
title="{data>title}">
</unified:CalendarAppointment>
</appointments>
</PlanningCalendarRow>
</rows>
</PlanningCalendar>
</VBox>
</semantic:FullscreenPage>
(以下簡稱「數據」的模式已經結合與metadata.xml中,並得到雙方Appointments.json和Employees.json)
其實,這段代碼在我的計劃中爲每位員工顯示Appointments.json中的兩項任務。我想綁定它,以便僅爲「HACHMI」的員工「APERCE」和「test2」預約「測試」,但我不能。
我相信這是可以做到的東西等同於JOIN的SQL數據庫,但我不覺得任何事情。我應該怎麼做?謝謝您的回答。
PS:我是法國人,如果你不明白我上面寫的,不好意思;如果你能用法語回答,那麼這樣做會對我的理解更好。
編輯:我已根據nistv4n的建議更正了代碼。現在,我得到了以下錯誤:未找到段「約會」 =>我的理解是,該段「約會」不存在,因爲它是「約會小號」,但我不」資源:
MockServer不知道我在哪裏忘了's'。
發生了以下問題:HTTP請求失敗404未找到{「error」:{「code」:404,「message」:{「lang」:「en」,「value」:「 'Appointment'}}}} =>我想它與前面的錯誤有關,因爲它要求'Appointment'而不是'Appointment s'?
REEDIT:我把's'放在正確的地方。現在我只有:無法讀取undefined =>屬性'getTime',因爲Overview.view中使用的模型存在問題。xml,可能在這裏,但是如果我使用「{Appointments/start}」,「{Appointments> start}」,「{start}」或「{/ Appointments> start}」,它是一樣的。
LASTEDIT:感謝nistv4n,我終於做到了。如果您遇到同樣的問題,我已經更新了上面的代碼。正確的代碼是PlanningCalendarRow =>約會= 「{路徑: '數據>約會'}」和統一:CalendarAppointment =>的startDate = 「{數據>開始}」等等
其實,引用nistv4n:「約會有一個相對的引用,內部屬性(開始,結束,標題)也有一個相對引用,包括模型名稱。」
startDate =「{data> start}」,endDate =「{data> end}」,title =「{data> title}」。 –
每個員工都有「測試」和「測試2」的任務。但是我只想爲「HACHMI」的「APERCE」和「test2」進行「測試」,對於其他員工則沒有。 – Nicaps
@Ash其實你是對的,問題在於PlanningCalendarRow。謝謝 ! – Nicaps