1

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));
},
3

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.

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.