【发布时间】:2019-07-04 11:50:41
【问题描述】:
我无法返回内部 observable
createItem -> 将创建项目(POST 请求) 该项目包含 ID 的响应表单,通过使用该 ID,我将附件添加到项目。
addAttachmentstoItem -> POST 请求
所选文件 -> 包含表单中的附件,我们正在循环访问每个文件并调用 addAttachmentstoItem 发布请求。
内部可观察对象的合并映射运算符无法返回可观察对象
this.sharepointService.createItem(this.itemData)
.pipe(
mergeMap (( response : Response) => {
this.lastItemCreatedId = response['d'].ID
this.selectedfile.forEach( (file) => {
let filename = file.name
let url = "_spPageContextInfo.webAbsoluteUrl"+"_api/web/lists/getByTitle('"+ libraryName +"')/items("+this.lastItemCreatedId+")/AttachmentFiles/add(FileName = '"+filename+"')"
return this.sharepointService.addAttachementstoItem(url,filename).subscribe( response => console.log("File Uploaded"))
})
}),
).subscribe()
sharepointService 中的代码:
createItem(itemData): Observable<Object> {
console.log("Inside postItem")
console.log(itemData.reqno)
var body = {
"__metadata" : {'type' : 'SP.Data.CustomListListItem'},
'Title' : 'first',
'Requisition_x0020_Number' : itemData.reqno,
'Site_x0020_Security_x0020_Groups' : itemData.sitesecuritygroups,
'User_x0020_Security_x0020_Groups' :itemData.usersecuritygroups,
'Attachments' : itemData.selectedfile
}
return this.http.post(this.baseUrl+"_api/web/lists/getbytitle('CustomList')/items",body)
}
addAttachementstoItem(url,selectedfile): Observable<Object> {
console.log(url)
return this.http.post(url,selectedfile)
}
我收到错误:“(响应:响应)=> void”类型的参数不可分配给“(值:响应,索引:数字)=> ObservableInput”类型的参数。 类型“void”不可分配给类型“ObservableInput”。
【问题讨论】: