0

Hi i have list of Ids checkedContacts and boxPack is also list of ids, i want to compare both of them and make true. if checkedContact id and boxpack id matches.

 <aura:attribute name="checkedContacts" type="Id[]" />

 handleApplicationEventFired : function(component, event) {

    var message = event.getParam("message");
    alert('message'+message)
    // set the handler attributes based on event data
    component.set("v.messageFromEvent", message);

      var a = component.get("v.checkedContacts");

    if(a.length != 0)
    {
    var boxPack = component.find("dependent");
    console.log('boxPack.len' + boxPack.length);
    if (!Array.isArray(boxPack)) {
        boxPack = [boxPack];
    }

        for (var i = 0; i < boxPack.length; i++) {
            alert('boxpack'+boxPack[i].get("v.text"));
            alert('checkedContacts'+(component.get("v.checkedContacts")[i]));
            if(JSON.stringify(component.get("v.checkedContacts")[i])==boxPack[i].get("v.text"))
            {
                alert('inside');
                 boxPack[i].set("v.value", true);
            }

    } 
    }

}

1 Answer 1

1

try the below

var a = component.get("v.checkedContacts");
boxPack.forEach(function(element,index, boxPack) {//loop through all elements
if(a.indexOf(element) > -1)//to check if each individual element of array is present in checked contacts
boxPack[index].set("v.value", true);//setting index attr for matching contacts
});
2
  • thank you, but it is not going in if loop.
    – Salesforce
    Commented Jun 6, 2017 at 4:33
  • I am assuming you are trying to check if each contact in boxpack array is present in checkedContacts and if yes you are setting arrays v.value to true. Post both the array content in your question.
    – RedDevil
    Commented Jun 6, 2017 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .