You need to sign in to do that
Don't have an account?
Øyvind Borgersen 10
Lightnin component metadata list
Hi,
I've created an controller to show the custom metadata values in a lightning component. The apex controller works fine, but the values are not shown in the list. Can someone please check where the error is in this code:
Apex class:
public with sharing class deadlineDatesController {
@AuraEnabled
public static List <DeadlineDate__mdt> getDeadlineDates() {
List<DeadlineDate__mdt> dlist =
[select label
value1__c,
value2__c
from DeadlineDate__mdt
limit 100];{
system.debug('Listvalues' + dlist);
return dlist;
}
}
}
Lightning component controller:
({
doInit: function(component, event, helper) {
// Fetch the account list from the Apex controller
var action = component.get("c.getDeadlineDates");
action.setCallback(this, function(data) {
component.set("v.dates", data.getReturnValue());
console.log('Returnvalue' + data.getReturnValue());
});
$A.enqueueAction(action);
},
})
Lightning component:
<aura:component controller="deadlineDatesController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name="deadline" type="DeadlineDate__mdt[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<!-- Use a data table from the Lightning Design System: https://www.lightningdesignsystem.com/components/data-tables/ -->
<table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
<thead>
<tr class="slds-text-heading_label">
<th scope="col"><div class="slds-truncate" title="Year">Year</div></th>
<th scope="col"><div class="slds-truncate" title="value1">value1</div></th>
<th scope="col"><div class="slds-truncate" title="value1">value2</div></th>
</tr>
</thead>
<tbody>
<!-- Use the Apex model and controller to fetch server side data -->
<aura:iteration items="{!v.dates}" var="date">
<tr>
<th scope="row">
<div class="slds-truncate" title="{!date.label}">{!date.label}</div></th>
<td><div class="slds-truncate" title="{!date.value1_c}">{!date.value1__c}</div></td>
<td><div class="slds-truncate" title="{!date.value2__c}">{!date.value2__c}</div></td>
<td>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
I've created an controller to show the custom metadata values in a lightning component. The apex controller works fine, but the values are not shown in the list. Can someone please check where the error is in this code:
Apex class:
public with sharing class deadlineDatesController {
@AuraEnabled
public static List <DeadlineDate__mdt> getDeadlineDates() {
List<DeadlineDate__mdt> dlist =
[select label
value1__c,
value2__c
from DeadlineDate__mdt
limit 100];{
system.debug('Listvalues' + dlist);
return dlist;
}
}
}
Lightning component controller:
({
doInit: function(component, event, helper) {
// Fetch the account list from the Apex controller
var action = component.get("c.getDeadlineDates");
action.setCallback(this, function(data) {
component.set("v.dates", data.getReturnValue());
console.log('Returnvalue' + data.getReturnValue());
});
$A.enqueueAction(action);
},
})
Lightning component:
<aura:component controller="deadlineDatesController" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
<aura:attribute name="deadline" type="DeadlineDate__mdt[]" />
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<!-- Use a data table from the Lightning Design System: https://www.lightningdesignsystem.com/components/data-tables/ -->
<table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
<thead>
<tr class="slds-text-heading_label">
<th scope="col"><div class="slds-truncate" title="Year">Year</div></th>
<th scope="col"><div class="slds-truncate" title="value1">value1</div></th>
<th scope="col"><div class="slds-truncate" title="value1">value2</div></th>
</tr>
</thead>
<tbody>
<!-- Use the Apex model and controller to fetch server side data -->
<aura:iteration items="{!v.dates}" var="date">
<tr>
<th scope="row">
<div class="slds-truncate" title="{!date.label}">{!date.label}</div></th>
<td><div class="slds-truncate" title="{!date.value1_c}">{!date.value1__c}</div></td>
<td><div class="slds-truncate" title="{!date.value2__c}">{!date.value2__c}</div></td>
<td>
</td>
</tr>
</aura:iteration>
</tbody>
</table>
</aura:component>
Greetings to you!
You are using dates in iteration, but you are not storing the list anywhere. You need to create an attribute for that.
<aura:attribute name="dates" type="DeadlineDate__mdt[]" />
Try below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
You are using dates in iteration, but you are not storing the list anywhere. You need to create an attribute for that.
<aura:attribute name="dates" type="DeadlineDate__mdt[]" />
Try below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
That solved it.