【发布时间】:2015-06-17 02:55:39
【问题描述】:
我将 Breeze 与支持附件的 SharePoint Online 列表一起使用。 Breeze 查询正确调用了 expand ,我可以通过 Browser 和 Fiddler 看到 JSON 与附件数据一起返回。但是,在 Breeze JavaScript 中创建的实体不包含 AttachmentFiles 的数据。它始终为空。这是 SP 适配器不支持的东西,还是我错误地定义了 AttachmentFiles 和 List 实体。我已经尝试了多种方法来定义关系,使用复杂类型和导航,使用自动生成 ID 和不使用自动生成 ID,但我遇到了困难。
Rest 请求如下所示: /_api/web/lists/getbytitle('Contacts')/items?$expand=Author/Id,AttachmentFiles&$select=Id,AuthorId,FirstName,Title,Email,Author,AttachmentFiles ,作者/用户名
附件是返回的 JSON 视图,以及映射的当前 Breeze 实体。
来自实体的片段
//attachments
addType({
name: 'AttachmentFiles',
dataProperties: {
ServerRelativeUrl: {
nullable: false
},
FileName: {
nullable: false
}
}
});
// create entity for contacts
addType({
name: 'Contacts',
defaultResourceName: 'getbytitle(\'Contacts\')/items',
dataProperties: {
Id: {
type: breeze.DataType.Int32
},
AuthorId: {
type: breeze.DataType.Int32
},
FirstName: {
nullable: false
},
Title: {
nullable: false
}, // this is actually the last name field in the list
Email: {
nullable: false,
validators: [breeze.Validator.emailAddress()]
},
Author: {
complexTypeName: "Author"
}
},
// Let model.validation add the requireReferenceEntity validators
navigationProperties: {
AttachmentFiles: {
type: 'AttachmentFiles',
hasMany: true
}
}
});
查看下方的 JSON 响应
{
"d": {
"results": [
{
"__metadata": {
"id": "388762a5-a565-4033-af90-5a2ea4cb1894",
"uri": "https://foo-616175366e015f.sharepoint.com/sites/DevSIte/BreezeSP2013Sample/_api/Web/Lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/Items(1)",
"etag": "\"3\"",
"type": "SP.Data.ContactsListItem"
},
"AttachmentFiles": {
"results": [
{
"__metadata": {
"id": "https://foo-616175366e015f.sharepoint.com/sites/DevSIte/BreezeSP2013Sample/_api/Web/Lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/Items(1)/AttachmentFiles('8328787dc792224f625c9645a45d01aa.jpg')",
"uri": "https://foo-616175366e015f.sharepoint.com/sites/DevSIte/BreezeSP2013Sample/_api/Web/Lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/Items(1)/AttachmentFiles('8328787dc792224f625c9645a45d01aa.jpg')",
"type": "SP.Attachment"
},
"FileName": "8328787dc792224f625c9645a45d01aa.jpg",
"ServerRelativeUrl": "/sites/DevSIte/BreezeSP2013Sample/Lists/Contacts/Attachments/1/8328787dc792224f625c9645a45d01aa.jpg"
},
{
"__metadata": {
"id": "https://foo-616175366e015f.sharepoint.com/sites/DevSIte/BreezeSP2013Sample/_api/Web/Lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/Items(1)/AttachmentFiles('Screen Shot 2015-04-23 at 10.28.35 AM.png')",
"uri": "https://foo-616175366e015f.sharepoint.com/sites/DevSIte/BreezeSP2013Sample/_api/Web/Lists(guid'df211835-f6df-4bb0-b7f0-0995c6ff8562')/Items(1)/AttachmentFiles('Screen%20Shot%202015-04-23%20at%2010.28.35%20AM.png')",
"type": "SP.Attachment"
},
"FileName": "Screen Shot 2015-04-23 at 10.28.35 AM.png",
"ServerRelativeUrl": "/sites/DevSIte/BreezeSP2013Sample/Lists/Contacts/Attachments/1/Screen Shot 2015-04-23 at 10.28.35 AM.png"
}
]
},
"Author": {
"__metadata": {
"id": "1fdc1547-d439-42bd-b3aa-b41e92c8ec6f",
"type": "SP.Data.UserInfoItem"
},
"UserName": "user@contoso.com"
},
"Id": 1,
"ID": 1,
"Title": "Alanso",
"AuthorId": 1073741823,
"FirstName": "Fernando",
"Email": "fernando.alonso@ferrari.it"
}
]
}
}
【问题讨论】:
标签: sharepoint breeze