Passing an aura:iterated list item to JS controller

The goal is to pass a “comment__c” rich text field on an iterated object to its JS controller to perform a string operation on it before it’s returned to limit a tooltip it is to appear into 250 characters. The console keeps printing truncString = [object Object] and I’m not sure if an object is getting passed and not a specific comment__c field or ?

Component

 <aura:iteration items="{!v.AddCommList}" var="item" indexVar="idx">
    <tr>
        <th scope="row">
            <a onclick="{!c.handleClick}"><div class="slds-truncate" title="{!item.Name}">
                <lightning:formattedText value="{!item.Name}"/></div></a></th>
        <td>
            <div class = "slds-truncate" data-record = "{!idx}"
                <lightning:formattedRichText aura:id = "Comment__c"
                                             value = "{!item.c}"
                                             data-record = "{!idx}" />
            </div>
        </td>

JS Controller

showCommentTip : function(component, event, helper){
    var cmpTarget = component.find('commentInfo');
    $A.util.removeClass(cmpTarget, 'slds-fall-into-ground');
    $A.util.addClass(cmpTarget, 'slds-rise-from-ground');

    var selectedItem = event.currentTarget;
    var index = selectedItem.dataset.record;
    var truncString = component.get("v.AddCommList.Comment__c")[index];
    component.set('v.commentTooltip', truncString.substr(0, 250));
},

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I would expect the code to look like this:

 var comment = component.get("v.AddCommList")[index].Comment__c;
 component.set('v.commentTooltip', comment.substr(0, 250));

The attribute holds the array, so once that is got you can index into it to get hold of a specific row. The row corresponds to an SObject and has a property available called Comment__c.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x