我正在尝试从照明组件下载几个文件。我无法将内容文档ID列表附加到url。请帮忙。
当我将多个ID添加到带有正斜杠的url中时,我能够一次下载所有文档。因此,我相信我可以将Ids列表直接传递给url。但无法做到。 我尝试了以下选项,但没有任何运气: 下载 下载`
COMPONENT:
<aura:component controller="MassFileDownload" implements="force:appHostable,force:hasRecordId,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global">
<aura:attribute name="listOfIds" type="String"/>
<aura:attribute name="resultList" type="List"/>
<aura:attribute name="isSuccess" type="Boolean"/>
<div class="slds-form-element">
<lightning:textarea name="list of ids" label="List of Ids" value="{!v.listOfIds}"/>
<aura:if isTrue="{!v.isSuccess}">
<!--<a href="{!'/sfc/servlet.shepherd/document/download/'+resultList}" target="_blank">DOWNLOAD</a>-->
<a href="{!'/sfc/servlet.shepherd/document/download/'&resultList&}" target="_blank">DOWNLOAD</a>
</aura:if>
</div>
<!-- BUTTON -->
<div class="slds-p-top_xx-large">
<button type="button" onclick="{!c.massDownload}" >Download</button>
</div>
</aura:component>
CONTROLLER:
({
massDownload : function(component, event, helper) {
console.log('111111111');
//var listIds = component.get("v.listOfIds");
helper.getSRId(component, event, helper);
}
})
HELPER:
({
getSRId : function(component,event,helper) {
console.log('2222222222');
console.log('33333333333'+ component.get("v.listOfIds"));
var action = component.get("c.GetContentDocLink");
console.log('4444444444' + action);
action.setParams({
'listLinkedEntity': component.get("v.listOfIds")
});
action.setCallback(this,function(response){
console.log('555555555555');
console.log('cow');
var state = response.getState();
if (state === "SUCCESS") {
console.log('dog');
var storeResponse = response.getReturnValue();
component.set("v.resultList", storeResponse);
component.set("v.isSuccess",true);
if (storeResponse.length == 0) {
console.log('snake' + storeResponse.length);
}
}else{
console.log('rabbit');
}
console.log('dog' + storeResponse.length);
// set searchResult list with return value from server.
//component.set("v.resultList", storeResponse);
console.log('owl' + storeResponse);
console.log('zebra' + component.get("v.resultList"));
})
$A.enqueueAction(action);
}
})
APEX:
public class MassFileDownload{
@AuraEnabled
public static List<String> GetContentDocLink(String listLinkedEntity){
list<String> returnList = new List<String>();
returnList=listLinkedEntity.split(',');
List<String> listWithSlash = new List<String>();
system.debug('aaaaaaaaa'+ listLinkedEntity + returnList);
List<String> listCDId = new List<String>();
List<String> listCDIdAll = new List<String>();
for(ContentDocumentLink cdl : [Select Id,ContentDocumentId,LinkedEntityId from ContentDocumentLink where LinkedEntityId in : returnList]){
system.debug('cccccccccccc'+cdl);
listCDId.add(cdl.ContentDocumentId);
}
for(Integer i = 0;i<listCDId.size();i++){
listWithSlash.add(listCDId[i]+'/');
//listWithSlash = listWithSlash+listCDId[i]+'/';
}
system.debug('bbbbbbbbbbb'+listCDId);
return listWithSlash;
}}
当我尝试保存组件时,出现以下错误:
未能保存MassDownload.cmp:期望为“&”,在表达式“ /sfc/servlet.shepherd/document/download/?”&resultList&:Source
的第45列中找到“ r”