11

related post

I am having the same issue. Trying to access array with dynamic index arrayList[index] (index from aura:iteration), but Salesforce doesn't support that.

Does anyone know how to do this?

Peace of code:

<aura:attribute name="iterList"             type="List" />
<aura:attribute name="phones"               type="String[]" />



<aura:iteration items="{! v.iterList }" var="val" indexVar="index">
    //some code here

            <ui:inputPhone label="{! v.labelName }" aura:id="phone" value="{! v.phones[index] }" class="form-control"/> 

   //some code here
</aura:iteration>

Error:

Result: [ERROR]: expecting a positive integer, found 'index' at column 11 of expression: v.phones[index]

4
  • looks like you will have to manipulate in your Javascript controller .How about breaking this only inputPhone to another component and use an attribute or use dynamic $A.createComponents Commented Aug 24, 2016 at 6:04
  • yeah, that's good idea, but not in my particular case. I've decided to change logic a little bit and iterate over phones array using var, Thanks anyway. Commented Aug 24, 2016 at 6:16
  • 2
    Still wondering , how we can iterate simultaneously over two arrays? Or there is no possible way to do it and we should use dynamic creation of the components in js controller. Commented Aug 24, 2016 at 14:43
  • For this, we can create an array of both the arrays like arr1, arr2, then iterate over 1 and push both in the array(new object with both arrays values for that index and so on) var finalArray = [];for(var i = 0; i < arr1.length; i++){ finalArray.push({arr1: arr1[i]m arr2: arr2[i]}) } and finally iterate over finalArray and access both the array values with arr1 & arr2 inside the aura:iteration. Commented Sep 28, 2018 at 6:55

3 Answers 3

0

I needed something similar so I used HTML input components instead of Ui:input components and used the data-selected-Index attribute for storing the index value

0

The easiest option is to create a component to display data within your iteration that would display whatever data you want.

0

You can manipulate the incoming json stored in the attribute iterList. Since in the attribute Phones, you have related values at the same index, you can add the phone value to the iterList attribute by creating a key value pair in the json.

For example, lets say your iterList structure is: [{"Name":"John","Age":"26"},{"Name":"Marie","Age":"21"},.......]

And your phones attribute is: ["12345678","87654532","98232233",...].

Then, we can write the following code to map the phones to the corresponding value in iterList:

var iterList=component.get("v.iterList");
var phones=component.get("v.phones");
for(var i in iterList){
    iterList[i]["Phone"]=phones[i];
}
component.set("v.iterList",iterList);

Now, you will have to modify your cmp file code as follows:

<aura:iteration items="{! v.iterList }" var="val" indexVar="index">
    //some code here

<ui:inputPhone label="{! v.labelName }" aura:id="phone" value="{!val.Phone}" class="form-control"/> 

   //some code here
</aura:iteration>
2
  • Please take a moment to familiarize yourself with the Stack Exchange policy on spam. Your company website is not relevant to this answer, and you seem to be trying to post from a corporate account.
    – David Reed
    Commented Feb 21, 2019 at 14:33
  • For now, I have edited your signature out of the post, as it is not relevant to the answer and the rest of it seems potentially helpful. Please do not include signatures in future posts, or they may indeed be flagged as spam for including a link to your website. Each post has a link to your profile under it. If you wish to link to your website, include such on your profile page.
    – Adrian Larson
    Commented Feb 21, 2019 at 14:45

You must log in to answer this question.

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