Skip to main content
rajni bhagat 님이 #Lightning Experience에 질문했습니다
I have a situation where i want to display the field value which should show sub string value of field inside aura iteration eg email field is test1.user1@gmail.com

i want to display value as test1.user1. ho can i achieve this?

<th data-label="Id" scope="row">

<div class="slds-truncate" title="Cloudhub">

<a href="{!'/one/one.app?⌗/sObject/'+ singleRec.Id + '/view'}" target="_blank">{!singleRec.Email}</a> </div>

</th>

 
답변 2개
  1. 2020년 4월 15일 오후 3:21
    Hi Divya,

    Please refer belwo code, where I have queried a list of contacts and have displayed their username by splitting the Email with '@':

     

    Controller.js:

    ({

    doInit : function(component, event, helper) {

    var action = component.get("c.getContacts"); //fetching a list of Contacts

    action.setCallback(this, function(response){

    if(response.getState() == "SUCCESS"){

    var result= response.getReturnValue();

    var lst = [];

    component.set("v.contcts", response.getReturnValue());

    for(var i=0; i<result.length; i++){

    let username = result[i].Email.split('@')[0];

    lst.push({value:username, key:result[i]});

    }

    component.set("v.myMap", lst);

    }

    });

    $A.enqueueAction(action);

    }

    })

    CMP:

    <aura:attribute name="myMap" type="Map"/>

    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <aura:iteration items="{!v.myMap}" var="mp" indexVar="key">

    <tr>

    <td title="Contact" style="width: 50%">

    {!mp.key.Id}<br/><br/>

    </td>

    <td title="Email" style="width: 50%">

    {!mp.value}

    </td>

    </tr>

    </aura:iteration>

     
0/9000