2

Is it possible to directly call a Lightning component controller function during each aura:iteration? I have everything stored as custom metadata and the Apex controller filters out the sObjects that match the criteria. I pass the List attribute into the JS controller which loops to look if the current iterated item is in the list and if so, enable the field. I was wanting something like,

<aura:iteration items="{!v.allAPIFields}" var="item">

    <!-- CALL CDEContentDocDetailsController.FindFieldsUpdate HERE? -->

    <div class="slds-grid">
        <div id="inputFieldsCol1" class="slds-col slds-p-horizontal_medium">
            <lightning:input label="{!item}"
                             aura:id="fieldInput"
                             disabled="{!isDisabled}"/>
        </div>
        <div id="inputFieldsCol2" class="slds-col slds-p-horizontal_medium">
            <lightning:input label="{!item}"
                             aura:id="fieldInput"
                             disabled="{!isDisabled}"/>
        </div>
    </div>
</aura:iteration>

My only other thought was to build a map and hoping I could use a "CONTAINS" in my component?

2

No, you can't call a method like that during the iteration. I'd imagine it probably be a huge performance sink anyways. You'll want to process the data in your controller/helper and then set the value. Something like this:

<aura:iteration items="{!v.allAPIFields}" var="item">
    <div class="slds-grid">
        <div id="inputFieldsCol1" class="slds-col slds-p-horizontal_medium">
            <lightning:input label="{!item.label}"
                             aura:id="fieldInput"
                             disabled="{!item.isDisabled}"/>
        </div>
        <div id="inputFieldsCol2" class="slds-col slds-p-horizontal_medium">
            <lightning:input label="{!item.label}"
                             aura:id="fieldInput"
                             disabled="{!item.isDisabled}"/>
        </div>
    </div>
</aura:iteration>

To actually map the data, use Array.prototype.map:

 allAPIFields = allAPIFields.map(function(item) { return { label: item, isDisabled: FindFieldsUpdate(item) } });

I'm not sure what that method is supposed to look like, but it sounds like you may also want to bulkify the method, especially if you're calling the server repeatedly.

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.