1

I have a Lightning component to display a list of Knowledge Articles. The code runs ok and seems to enter the <aura:iteration as the colons are displayed and looking at the debug log the query is returning results however the fields themselves like Title are not displayed when I run this in developer console.

component

<aura:component description="ArticleList" implements="forceCommunity:availableForAllPageTypes"  controller="ArticleListController">

<aura:attribute name="articles" type="SObject[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<aura:iteration var="article" items="{!v.articles}">
    <p>{!article.Id} : {!article.Title} : {!article.ArticleType}</p>
</aura:iteration>

</aura:component>

controller

({

doInit: function(component, event){
    var action = component.get("c.getArticles");
    action.setCallback(this, function(response){
    component.set("v.articles", response.getReturnValue());

    });
 $A.enqueueAction(action);
}

})

apex controller

public with sharing class ArticleListController {

@AuraEnabled
public static List<List<SObject>> getArticles() {
    String searchVar = 'Unpredictable';
    List<List<SObject>> articles = [FIND :searchVar RETURNING      KnowledgeArticleVersion
    (Id, Title, ArticleType WHERE PublishStatus='online' AND Language = 'en_US' AND ArticleType IN ('Knowledge__kav','Attachment__kav'))];
    return articles;

}

}
1
  • You're returning a List of Lists from your controller but looking at your Lightning attribute, you're expecting only a List. You may want to restructure your return from getArticles to return a List. Feb 15, 2017 at 23:11

1 Answer 1

0

You will need to refactor your code to return a strict list of sObject rather than list< list< sobject>>

@AuraEnabled
 public static List<SObject> getArticles() {
    String searchVar = 'Unpredictable';
    list<Sobject> lstresult = new list<Sobject>();
    List<List<SObject>> articles = [FIND :searchVar RETURNING      KnowledgeArticleVersion
           (Id, Title, ArticleType WHERE PublishStatus='online' AND Language = 'en_US' AND ArticleType IN ('Knowledge__kav','Attachment__kav'))];
   lstresult.add(articles[0]);
   lstresult.add(articles[1]);
   return lstresult;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.