【发布时间】:2016-06-20 14:16:07
【问题描述】:
我在一家公司实习,我必须使用 SAPUI5 框架编写 JS 代码。这对我来说是全新的,这就是我遵循http://sapui5.hana.ondemand.com 教程的原因。但是现在我有一个问题,我在网上找不到任何建议,而且我不能总是让我的同事帮助我,他们也有工作......
我必须与许多员工及其任务一起制定计划。我使用带有 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"
}]
(如您所见,EmployeeID 存在于 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 中针对我计划中的每个员工的两个任务。我想绑定它以便只为员工“APERCE”预约“test”,只为“HACHMI”预约“test2”,但我不能。
我相信可以为 SQL 数据库执行与 JOIN 等效的操作,但我没有找到任何相关信息。我应该怎么做?谢谢你的回答。
PS:我是法国人,如果你不明白我上面写的内容,对不起;如果你能用法语回答,那就这样做,这对我的理解会更好。
编辑:我已根据 nistv4n 的建议更正了代码。现在我收到以下错误:
MockServer: Resource not found for the segment 'Appointment' => 我知道,'Appointment' 部分不存在,因为它是 'Appointments',但我不知道在哪里我忘记了's'。
出现以下问题:HTTP request failed404,Not Found,{"error":{"code":404,"message":{"lang":"en","value":"Resource not found for the segment 'Appointment'"}}} => 我猜这与上一个错误有关,因为它请求的是 'Appointment' 而不是 'Appointments' ?
重新编辑:我把“s”放在正确的位置。现在我只有:无法读取未定义的属性'getTime' =>,因为Overview.view.xml中使用的模型可能存在问题,但如果我使用它也是一样的:“{Appointments/start}” 、“{Appointments>start}”、“{start}”或“{/Appointments>start}”。
LASTEDIT : 多亏了 nistv4n,我终于做到了。如果您有同样的问题,我已经更新了上面的代码。正确的代码在 PlanningCalendarRow => appointments="{path : 'data>Appointments'}" 和统一中:CalendarAppointment => startDate="{data>start}" 等等……
实际上,引用 nistv4n :“约会有相对引用,内部属性(开始、结束、标题)也有相对引用,包括模型名称。”
【问题讨论】:
-
startDate="{data>start}", endDate="{data>end}", title="{data>title}" 怎么样。
-
每个员工都有任务“test”和“test2”。但我只希望“APERCE”的“测试”和“HACHMI”的“test2”,而不是其他员工。
-
@Ash 实际上你是对的,问题出在 PlanningCalendarRow 中。谢谢!
标签: javascript json xml metadata sapui5