Skip to main content
formatted code
Source Link

component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
    //If input is an if(Array.isArray(component))array, then just return it
    //If only one element found, then convert it returninto component;a single element array anyway
    if(Array.isArray(component))  
   else     return component;
    else  
        return component? [component] : [];
    },

Use it like so:

var recordfinallist = component.get('v.attributename');                   
                for (var i = 0; i < recordfinallist.length; i++) {                       
                    if (recordfinallist[i].isvalid__C==isvalid__C == true){                                                      
                        helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);                               
                        }                                  
                    }                                     
                }

component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
        if(Array.isArray(component)) 
            return component;
        else 
            return component? [component] : [];
    },

Use it like so:

var recordfinallist = component.get('v.attributename');                   
                for (var i = 0; i < recordfinallist.length; i++) {                       
                    if (recordfinallist[i].isvalid__C== true){                                                      
                        helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);                               
                        }                                  
                    }                                     
                }

component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
    //If input is an array, then just return it
    //If only one element found, then convert it into a single element array anyway
    if(Array.isArray(component))  
        return component;
    else  
        return component? [component] : [];
},

Use it like so:

var recordfinallist = component.get('v.attributename');
for (var i = 0; i < recordfinallist.length; i++) {
    if(recordfinallist[i].isvalid__C == true)
        helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
}
New answer
Source Link

Trycomponent.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
        if(Array.isArray(component)) 
            return component;
        else 
            return component? [component] : [];
    },

Use it like so:

var recordfinallist = component.get('v.attributename');                   
                for (var i = 0; i < recordfinallist.length; i++) {                       
                    if (recordfinallist[i].isvalid__C== true){                                                      
                        helper.arrayfy(component.find("checkBox"))[i].set("v.checked"value", true);                               
                        }                                  
                    }                                     
                }

Try this:

component.find("checkBox")[i].set("v.checked", true);

component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
        if(Array.isArray(component)) 
            return component;
        else 
            return component? [component] : [];
    },

Use it like so:

var recordfinallist = component.get('v.attributename');                   
                for (var i = 0; i < recordfinallist.length; i++) {                       
                    if (recordfinallist[i].isvalid__C== true){                                                      
                        helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);                               
                        }                                  
                    }                                     
                }
Post Undeleted by Lightning Evangelist
Post Deleted by Lightning Evangelist
Source Link

Try this:

component.find("checkBox")[i].set("v.checked", true);