【发布时间】:2020-05-08 00:25:18
【问题描述】:
我有多个附件链接和附件名称。这是控制台显示的内容:
问题是只显示最后一个链接和名称:
我在模板中使用这个:
<div class="d-inline col-lg-20 col-md-60 col-sm-40" padding="20px" >
<th>Files</th>
<tr>
<div class="d-inline col-lg-20 col-md-60 col-sm-40" padding="20px">
{{attachmentName}}
{{attachmentUrl}}
</div>
</tr>
</div>
数据中的这个:
data() {
return {
selectedFile: "",
progress: 0,
attachmentName: [],
attachmentUrl: [],
};
},
这在 JavaScript 中:
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items('" + itemId + "')/AttachmentFiles",
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=nometadata" },
success: function (data) {
$(data.value).each(function (i) {
attachments.items.push({
extension: this.FileName.substring(this.FileName.lastIndexOf('.') + 1),
name: this.FileName,
path: this.ServerRelativeUrl
});
attachmentLink = "site.sharepoint.com" + this.ServerRelativeUrl;
attachmentName = this.FileName;
self.attachmentUrl = attachmentLink;
self.attachmentName = attachmentName;
attachments.count++;
console.log("attachments: " + attachmentLink);
console.log("name: " + attachmentName);
});
}
});
问题在于这两行:
self.attachmentUrl = attachmentLink;
self.attachmentName = attachmentName;
我不知道如何解决这个问题,因为 console.log 显示 2 项,而模板只显示最后一项。我使用 for 循环进行了一些实验,但无法将所有附件链接和名称都放入模板中。
感谢任何帮助!
【问题讨论】:
标签: javascript arrays vue.js templates reference