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
.12.12 

I've a json and i'm using aura:iteration to display values in <tbody> but i don't want to show all the values in table

I want only one value from the json but i'm getting all the values how can i stop iteration or is there any way to show only one row like keeping size please help to find the solution

Thank you in Advance,

<tbody>
                        <aura:iteration items="{!v.jsonValues}" var="item" indexVar="rowIndex">  
                            <tr data-data="{!rowIndex}">
                                <td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
                                    <span class="slds-grid slds-grid_align-spread">
                                        <div class="slds-truncate">                                        
                                            <span class="slds-truncate">{!item.firstName}</span>
                                        </div>
                                    </span>                            
                                </td>
                            </tr>
                        </aura:iteration>
                    </tbody>

Original Output:-
      Ramesh
      Suresh
      Rakesh

Expected Output:-
    Ramesh
Best Answer chosen by .12
Maharajan CMaharajan C
Hi, 

Please try the below any one of the way:
 
<tbody>
	<aura:iteration items="{!v.jsonValues}" var="item" indexVar="rowIndex"> 
		<aura:if isTrue="{! rowIndex == 0 }">
			<tr data-data="{!rowIndex}">
				<td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
					<span class="slds-grid slds-grid_align-spread">
						<div class="slds-truncate">                                        
							<span class="slds-truncate">{!item.firstName}</span>
						</div>
					</span>                            
				</td>
			</tr>
		</aura:if>
	</aura:iteration>
</tbody>

OR
 
<tbody>
    <aura:if isTrue="{!not(empty(v.jsonValues))}">
        <tr>
            <td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
                <span class="slds-grid slds-grid_align-spread">
                    <div class="slds-truncate">                                        
                        <span class="slds-truncate">{!jsonValues[0].firstName}</span>
                    </div>
                </span>                            
            </td>
        </tr>
    </aura:if>
</tbody>

Thanks,
Maharajan.C

All Answers

Maharajan CMaharajan C
Hi, 

Please try the below any one of the way:
 
<tbody>
	<aura:iteration items="{!v.jsonValues}" var="item" indexVar="rowIndex"> 
		<aura:if isTrue="{! rowIndex == 0 }">
			<tr data-data="{!rowIndex}">
				<td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
					<span class="slds-grid slds-grid_align-spread">
						<div class="slds-truncate">                                        
							<span class="slds-truncate">{!item.firstName}</span>
						</div>
					</span>                            
				</td>
			</tr>
		</aura:if>
	</aura:iteration>
</tbody>

OR
 
<tbody>
    <aura:if isTrue="{!not(empty(v.jsonValues))}">
        <tr>
            <td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
                <span class="slds-grid slds-grid_align-spread">
                    <div class="slds-truncate">                                        
                        <span class="slds-truncate">{!jsonValues[0].firstName}</span>
                    </div>
                </span>                            
            </td>
        </tr>
    </aura:if>
</tbody>

Thanks,
Maharajan.C
This was selected as the best answer
.12.12
Hey Maharajan.C 

Thanks for the reply i've got the  solution and it is same as your second one which you have sent.

Thanks for the quick reply Thank you very much.
Maharajan.C
Suraj Tripathi 47Suraj Tripathi 47
Hi  .12,

If you want only a single value then you don't need to iterate over it just simply create a new attribute and 
store the required JSON value into it and simply print on UI.


If you find your Solution then mark this as the best answer. 


Thank you!

Regards 
Suraj Tripathi

 
.12.12

What if i have two json files i have to use aura if and match two values and show YES or else NO how it is possible can you explain if possible 

 

Because i've tried the below code but it is not working and always displaying only else part 


<aura:if isTrue="{!firstjson.firstName== '!secondjson.firstName'}" >
                                                <td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
                                                    <span class="slds-grid slds-grid_align-spread">
                                                        <div class="slds-truncate">                                        
                                                            <span class="slds-truncate">Yes</span>
                                                        </div>
                                                    </span>                            
                                                </td>
                                                <aura:set attribute="else">
                                                    <td role="gridcell" tabindex="-1" data-label="Record Type Name">                            
                                                        <span class="slds-grid slds-grid_align-spread">
                                                            <div class="slds-truncate">                                        
                                                                <span class="slds-truncate">No</span>
                                                            </div>
                                                        </span>                            
                                                    </td>
                                                </aura:set>
                                            </aura:if>

Maharajan CMaharajan C
Can you please update the if condition... It looks like not written properly in above code...
 
<aura:if isTrue="{! firstjson.firstName == secondjson.firstName}" >

Thanks,
Maharajan.C

 
.12.12
Hlo Maharajan.C

I've updated that aura:if which you have shared but it is also displaying only ELSE part if statement is not working
Pmmodi SchemesPmmodi Schemes
Get the latest information about State & Central Government Schemes at Yogimodiyojana (https://yogimodiyojana.in/)