function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Niki Shah 12Niki Shah 12 

how to display data in output text from object in lightning component

controller

({
    doInit : function(component, event, helper) {
        
       var action = component.get("c.getProjectDetails");
      //action.setparm
        action.setCallback(this,function(response){
             if (response.getState() === "SUCCESS"){
                    component.set("{!v.contacts}",response.getReturnValue());
                }
            
       
            var dodge__DR_NBR__c = response.getState();
            if (dodge__DR_NBR__c === "SUCCESS") {
               
                 component.set("v.contacts", response.getReturnValue());
                    
               
                console.log(response.getReturnValue());
            }
            
            }
        );
        
    
    
        
        var action1 = component.get("c.getProjectList");
        action1.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    component.set("{!v.details}",response.getReturnValue());
                }
     
            var dodge__DR_NBR__c = response.getState();
            if (dodge__DR_NBR__c === "SUCCESS") {
                component.set("v.details", response.getReturnValue());
                console.log(response.getReturnValue());
            }
            
            }
        );
 
         $A.enqueueAction(action);
         $A.enqueueAction(action1);
        
       
         

 
    }
})

component

<aura:component controller="LeadRep" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global"  >
  <aura:attribute name="contacts" type="String" />
    <aura:attribute name="details" type="String" default="hello"/>
    
    


    
 

 
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
   <!-- Use a data table from the Lightning Design System: https://www.lightningdesignsystem.com/components/data-tables/ -->
       
       
         
   
 <article class="slds-card">
  <div class="slds-card__header slds-grid">
      
      
    <header class="slds-media slds-media_center slds-has-flexi-truncate">
      <div class="slds-media__figure">
        <span class="slds-icon_container slds-icon-standard-account" title="Rep_Lead">
          <lightning:icon iconName="doctype:image" alternativeText="Doc image" />
          <span class="slds-assistive-text">Rep Lead</span>
        </span>
      </div>
      <div class="slds-media__body">
        <h2 class="slds-card__header-title">
          <a href="javascript:void(0);" class="slds-card__header-link slds-truncate" title="Rep_Lead">
            <span>Rep Lead</span>
          </a>
        </h2>
      </div>
    </header>
      
  
  </div>
  <div class="slds-card__body slds-card__body_inner">Card Body</div>
  </article>  
         
         
 <div class="slds-box slds-theme_default">        
     
 <h2>Contact Information</h2>
     
      
     <div class="slds-grid slds-gutters">
  <div class="slds-col">
      
 
 <span><ui:inputText label="Dodge Report Number"  value="{!v.contacts.dodge__DR_NBR__c}" /></span>
   
        <span><span><ui:inputText label="Project name" value="{!v.contacts.dodge__TITLE__c}"/></span></span>
<span><span><ui:inputText label="Project name" value="{!detail.dodge__PROJECT_ROLE__c}"/></span></span>
        </div>
  
</div>   

     
</div>
     
    <table class="slds-table slds-table_cell-buffer slds-table_bordered">
  <thead>
    <tr class="slds-line-height_reset">
        
        
              <th class="" scope="col">
        <div class="slds-truncate" title="dodge__TITLE__c">dodge TITLE</div>
      </th>
      <th class="" scope="col">
        <div class="slds-truncate" title="dodge__PROJECT_ROLE__c">Project Role</div>
      </th>
      <th class="" scope="col">
        <div class="slds-truncate" title="dodge__DR_NBR__c">Dodge Report Number</div>
      </th>
      <th class="" scope="col">
        <div class="slds-truncate" title="dodge__P_ADDR_LINE1__c">Address1</div>
      </th>
      <th class="" scope="col">
        <div class="slds-truncate" title="Project Opportunity">Project Opportunity</div>
      </th>
     
    </tr>
  </thead>
  <tbody>
      <aura:iteration items="{!v.details}" var="detail"> 
       <aura:iteration items="{!v.contacts}" var="contact">    
      
apex class
public class LeadRep {

    
    
@AuraEnabled
   
    Public static list<dodge__DODGE_PROJECT__c>getProjectDetails(){
        return [SELECT dodge__TITLE__c,dodge__DR_NBR__c,dodge__P_ADDR_LINE1__c FROM dodge__DODGE_PROJECT__c where dodge__DR_NBR__c='201800529072'];
    }

   /* @AuraEnabled 
  Public static list<dodge__DODGE_ROLE__c>getProjectList() {
      return [SELECT dodge__PROJECT_ROLE__c FROM dodge__DODGE_ROLE__c where dodge__DR_NBR__c='201800529072'];
  }*/
    @AuraEnabled 
   Public static list<dodge__DODGE_ROLE__c>getProjectList() {
      return [SELECT dodge__PROJECT_ROLE__c,dodge__DODGE_ACCOUNT__c,dodge__DODGE_CONTACT__r.dodge__FIRM_NAME__c FROM dodge__DODGE_ROLE__c where dodge__DR_NBR__c='201800529072']; 
   }
 /* @AuraEnabled 
  Public static list<dodge__Dodge_Project_Lead__c>getDodgeProjectLeadList() {
     return [SELECT dodge__P_ADDR_LINE1__c FROM dodge__Dodge_Project_Lead__c where dodge__DR_NBR__c='201800529072']; 
  }*/
    

    
}
      
    <tr class="slds-hint-parent">
     
      <td>
        <div class="slds-truncate" title="{!contact.dodge__TITLE__c}">{!contact.dodge__TITLE__c}</div>
      </td>
      <td>
        <div class="slds-truncate" title="{!detail.dodge__PROJECT_ROLE__c}">{!detail.dodge__PROJECT_ROLE__c}</div>
      </td>
      <td>
        <div class="slds-truncate" title="{!contact.dodge__DR_NBR__c}">{!contact.dodge__DR_NBR__c}</div>
      </td>
      <td>
        <div class="slds-truncate" title="{!contact.dodge__P_ADDR_LINE1__c}">{!contact.dodge__P_ADDR_LINE1__c}</div>
      </td>
      <td>
        <div class="slds-truncate"  title="Create"><a href="swifterfans--lf1.lightning.force.com/lightning/o/Opportunity/list?filterName=Recent">Create</a></div>
      </td>
      
    </tr>
           
    </aura:iteration>
     
    </aura:iteration>
   
  </tbody>
</table>
    
    
  
</aura:component>        
         
      
     
       
     
     
            
            
            
            
            
     
    
   
 
 
 

 
     




 
Ramesh DRamesh D
Aura Componet:
<aura:component description="ShowContacts"
               implements="force:appHostable"
                access="global"
                controller="CommunityCreateNew">    
    <aura:attribute name="userDetails" type="List" />
    <aura:handler name="init"
                  value="{!this}"
                  action="{!c.doInit}"/> 
    <aura:iteration items="{!v.userDetails}" var="item">
        {!item.Name} <br/>
    </aura:iteration>
</aura:component>

Js Controller:
({
    doInit : function(component, event, helper) {
        console.log('inside');
        var action = component.get("c.getContacts");
        //action.setparm
        action.setCallback(this,function(response){
            if (response.getState() === "SUCCESS"){
                 alert('success');
                component.set("v.userDetails",response.getReturnValue());
            }
            else
            {
                alert('Error');
            }
        });
        $A.enqueueAction(action);
    }
});

Apex Controller:
@AuraEnabled    
    Public static list<contact> getContacts(){
        return [SELECT id,name from contact limit 10];
    }

OutPut:
User-added image

I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D
Niki Shah 12Niki Shah 12
my data table working is good but Inputtext is not working
Ramesh DRamesh D
Hi Niki,
What do you mean by Inputtext not working? can you please elobrate your problem so we can provide solution 

Thanks
Ramesh
Niki Shah 12Niki Shah 12
Thanks for helping me .I am trying to say i fetch data from object and i want to display data in inputtext .but the value is not coming in input text 
Ramesh DRamesh D
Try this and let me know 
<aura:attribute name="userDetails" type="List" />
    <aura:attribute name="columns" type="List"/>
    <aura:handler name="init"
                  value="{!this}"
                  action="{!c.doInit}"/> 
    <div class="slds-p-around_medium lgc-bg" style="height: 300px;">
        <lightning:datatable
                             aura:id="accountDataTable"
                             columns="{! v.columns }"
                             data="{! v.userDetails }"
                             keyField="Id"
                             onsave ="{!c.onSave}"
                             hideCheckboxColumn="true" />
    </div>

JS:
({
    doInit : function(component, event, helper) {
        
        component.set('v.columns', [
            {label: 'Name', fieldName: 'Name', editable:'true', type: 'text'},
            {label: 'Email', fieldName: 'Email', editable:'true', type: 'email'}
        ]);        
        var action = component.get("c.getContacts");
        //action.setparm
        action.setCallback(this,function(response){
            if (response.getState() === "SUCCESS"){
                component.set("v.userDetails",response.getReturnValue());
            }
            else
            {
                alert('Error');
            }
        });
        $A.enqueueAction(action);
    }
});

Output: 
User-added image

Thanks
Ramesh