问题描述
我正在创建一个spfx Web部件,并且需要知道如何将更多文件添加到现有文件数组中。 用户将单击带有文件附件的现有SharePoint项目。然后,将这些附件显示给用户。我希望用户能够单击按钮以将更多文件添加到现有阵列,以便可以将它们提交到列表(作为对项目的更新)。 下面是我使用的功能,因此用户可以使用按钮来附加多个文件:
private _addFile = (event) => {
if(this.state.fileArray){
//I'm guessing that here should be an alternative to the below,considering existing files,and not overwriting them when adding subsequent files.
} else {
let resultFile = event.target.files;
let fileInfos = [];
for (var i = 0; i < resultFile.length; i++) {
var resfile = resultFile[i];
var reader = new FileReader();
reader.onload = ((file) => {
return (e) => {
//Push the converted file into array
fileInfos.push({
"name": file.name,"content": e.target.result
});
};
})(resfile);
reader.readAsArrayBuffer(resfile);
// @ts-ignore
const fileListToArr = Array.from(resultFile);
this.setState({
fileArray: fileListToArr
});
}
this.setState({
fileInfos,});
}
}
我将创建一个“更新”按钮,用户可以提交新的文件数组。例如,我将使用:
web.lists.getByTitle("ListToUpdate").items.getById(this.state.Id).attachmentFiles.addMultiple(fileInfos);
我担心如果将上面的代码行放入更新函数中,它将创建一个新的列表项,而不是更新该项。
此致
T
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)