1

I have an attribute of type integer.

<aura:attribute name="selectedRowNum" type="integer"  />

I also have an iteration component in which I get the index of the current object that is being iterated through javascript, code is below on how I get that

var selectedItem = event.currentTarget; // Get the target object
    var index2 = selectedItem.dataset.record; // Get its value i.e. the index This is because in the iterration i used index on it
    var selectedacc = component.get("v.Accounts")[index2]; // Use it retrieve the stored record

I then store the index in the integer attribute

    var selectedRowNum = component.get("v.selectedRowNum");
        var number = component.get("v.index");
component.set("v.selectedRowNum", number);

This is my following code in the lightning component that I am having trouble with

                <aura:iteration var="account" items="{!v.Accounts}" indexVar="idx">
                    <tr class="slds-hint-parent">
                        <th role="gridcell">
                            <div class="slds-truncate" title="Acc"><a href="{!'/'+ account.Id }" target="_blank" tabindex="-1">{!account.Name} {!idx == v.selectedRowNum} <p>{!v.selectedRowNum} + {!idx} +{!v.index} </p></a></div>
                        </th>
                        <td role="gridcell">
                            <lightning:layoutItem size="4">
                                <div>
                                    <aura:if isTrue = "{!idx == v.selectedRowNum}">
                                        <!-- show nothing if the row is selected -->

                                        <aura:set attribute="else">                                        
                                            <c:customLookupComp objectAPIName="Master_Customer__c"
                                                                iconName="standard:account"
                                                                selectedRecord="{!v.selectedLookUpRecord}"
                                                                label="Search"
                                                                fieldAPIName="Id"
                                                                resultField1="Master_Customer__c"
                                                                resultField2=""
                                                                showlabel="false"
                                                                />
                                            <force:inputField  value="{!v.selectedLookUpRecords}"/>
                                        </aura:set>
                                    </aura:if>
                                </div>
                            </lightning:layoutItem>
                        </td>

As you can see I output what the current values of the index of the iteration component and the attribute. They match... But the aura if comparasion comes out false..

so !idx == v.selectedrownum always comes out false even though they show the same two numbers. I believe the data types are not the same and that is why the compare fails. If I were to hardcore the selectedrownum with a 0 then the aura if is valid( only for the index 0 for obvious reasons). Can I get some help on make sure these javascript integers match the integers the iteration component outputs? Has anyone else ran into this issue?

Thanks

8
  • 1
    Try type="Integer" instead of type="integer" Oct 15, 2018 at 13:03
  • 3
    Will try this, why would this be an issue though? Oct 15, 2018 at 13:05
  • 4
    Lightning is case sensitive. If it cannot find proper type it uses default object Oct 15, 2018 at 13:08
  • 1
    Lightning is case sensitive so , change it to Integer and you can try <aura:if isTrue="{!equals(v.selectedRowNum, idx)}" /> Oct 16, 2018 at 9:26
  • @SagarHinsu I have tried this and that expression and it works only if I had code the number to a zero. I think the issue is in this line. component.set("v.selectedRowNum", index2); if you look at the above code you will see how I retrieve this variable. The variable if you output it in a console comes out to whatever row you are on (0, 1, 2) and I compare it to the selectedrow num. Both numbers are zero on the first row but the aura if does not evaluate. However if I change the line to component.set("v.selectedRowNum", 0); the aura if works.. Oct 16, 2018 at 12:11

1 Answer 1

0

I have found the problem.

idx comes over as a string so we have to convert it in javascript to a number by using

Number()

this works. thanks everyone

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .