You need to sign in to do that
Don't have an account?
satish wagh
Uncaught Error in $A.getCallback() [Cannot read property 'label' of undefined] Callback failed:
I have created the Multiselect picklist component and got above error while loading component. Any help would be appreciated!.
Please see below code:
Client Side Controller file :
({
doInit:function(component,event,helper){
helper.getOpetionsHelper(component);
},
openDropdown:function(component,event,helper){
$A.util.addClass(component.find('dropdown'),'slds-is-open');
$A.util.removeClass(component.find('dropdown'),'slds-is-close');
},
closeDropDown:function(component,event,helper){
$A.util.addClass(component.find('dropdown'),'slds-is-close');
$A.util.removeClass(component.find('dropdown'),'slds-is-open');
},
selectOption:function(component,event,helper){
var label = event.currentTarget.id.split("#BP#")[0];
var isCheck = event.currentTarget.id.split("#BP#")[1];
helper.getOpetionsHelper(component,label,isCheck);
}
})
Helper File :
({
getOpetionsHelper: function(component)
{
var action = component.get("c.getOptions");
action.setCallback(this, function(response) {
var state = response.getState();
var optionResult = response.getReturnValue();
console.log('response '+JSON.stringify(optionResult));
var opt = new Array();
for(var i=0;i<=optionResult.length;i++){
opt.push({isChecked:optionResult[i].isChecked,label:optionResult[i].label});
}
component.set("v.options",opt);
});
Server Side Controller :
public class MultiSelectPicklistCls {
@AuraEnabled
public static List<PickListOptions> getOptions()
{
List<PickListOptions> optList = new List<PickListOptions>();
optList.add(new PickListOptions('Option 1',false));
optList.add(new PickListOptions('Option 2',true));
optList.add(new PickListOptions('Option 3',false));
return optList;
}
// wrapper class
public class PickListOptions
{
@AuraEnabled
public String label {get;set;}
@AuraEnabled
public boolean isChecked {get;set;}
public PickListOptions(String label,boolean isChecked){
this.label = label;
this.isChecked = isChecked;
}
}
}
Please see below code:
Client Side Controller file :
({
doInit:function(component,event,helper){
helper.getOpetionsHelper(component);
},
openDropdown:function(component,event,helper){
$A.util.addClass(component.find('dropdown'),'slds-is-open');
$A.util.removeClass(component.find('dropdown'),'slds-is-close');
},
closeDropDown:function(component,event,helper){
$A.util.addClass(component.find('dropdown'),'slds-is-close');
$A.util.removeClass(component.find('dropdown'),'slds-is-open');
},
selectOption:function(component,event,helper){
var label = event.currentTarget.id.split("#BP#")[0];
var isCheck = event.currentTarget.id.split("#BP#")[1];
helper.getOpetionsHelper(component,label,isCheck);
}
})
Helper File :
({
getOpetionsHelper: function(component)
{
var action = component.get("c.getOptions");
action.setCallback(this, function(response) {
var state = response.getState();
var optionResult = response.getReturnValue();
console.log('response '+JSON.stringify(optionResult));
var opt = new Array();
for(var i=0;i<=optionResult.length;i++){
opt.push({isChecked:optionResult[i].isChecked,label:optionResult[i].label});
}
component.set("v.options",opt);
});
Server Side Controller :
public class MultiSelectPicklistCls {
@AuraEnabled
public static List<PickListOptions> getOptions()
{
List<PickListOptions> optList = new List<PickListOptions>();
optList.add(new PickListOptions('Option 1',false));
optList.add(new PickListOptions('Option 2',true));
optList.add(new PickListOptions('Option 3',false));
return optList;
}
// wrapper class
public class PickListOptions
{
@AuraEnabled
public String label {get;set;}
@AuraEnabled
public boolean isChecked {get;set;}
public PickListOptions(String label,boolean isChecked){
this.label = label;
this.isChecked = isChecked;
}
}
}
Hi Satish,
You need to change this part of your code to fix this error
Since you're setting i=0, you need to remove the <= and use = for the comparison.
Hope this helps.
All Answers
Hi Satish,
You need to change this part of your code to fix this error
Since you're setting i=0, you need to remove the <= and use = for the comparison.
Hope this helps.