0

I am trying to dynamically populate data in a lightning componnet

and I getting error as Expecting Integer, while the same code works in visualforce - qili.planMap[plan]

Not able to use this as well - >{!qli.planMap[{!plan}]}

This is COMPILE Error

ERROR MESSAGE- expecting a positive integer, found 'plan' at column 13 of expression: qli.planMap[plan]: Source

   var action = component.get("c.getFamilyDetails");       
      action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            var resJson = response.getReturnValue();
            console.log('MVK Family Details-->'+JSON.stringify(resJson));
            var highestFamiyPlanKey = resJson[0].highestPlan;
            component.set("v.selectedPlanValue",highestFamiyPlanKey);
            console.log('Highest Plan Key-->'+highestFamiyPlanKey);
            var highestFamilyTotal = resJson[0].planTotal[highestFamiyPlanKey];
            console.log('MVK total-->'+highestFamilyTotal);
            component.set("v.familyTotal",highestFamilyTotal);
            component.set("v.quoteLinteItems",resJson);
            console.log('resJson PlanMap-->'+resJson[0].PlanMap);
        }

Json Format:--

[  
   {  
      "Emp_dep_Id":"0032200000ADlc1AAD",
      "highestPlan":"Gold",
      "Name":"New Test Employee",
      "planMap":{  
         "Silver":125,
         "Gold":423
      },
      "planTotal":{  
         "Silver":596,
         "Gold":1688
      },
      "seq_number":1
   },
   {  
      "Emp_dep_Id":"0032200000ADltqAAD",
      "highestPlan":"Gold",
      "Name":"Test Dep Dep",
      "planMap":{  
         "Silver":235,
         "Gold":523
      },
      "planTotal":{  
         "Silver":596,
         "Gold":1688
      },
      "relation":"Spouse"
   },
   {  
      "Emp_dep_Id":"0032200000ADmNZAA1",
      "highestPlan":"Gold",
      "Name":"Mangesh Khapre Khapre",
      "planMap":{  
         "Silver":236,
         "Gold":742
      },
      "planTotal":{  
         "Silver":596,
         "Gold":1688
      },
      "relation":"Child"
   }
]

Can you please help

                    <aura:iteration items="{!v.quoteLinteItems}" var="qli">
                        <tr>
                            <td><a href="javascript:void(0);" class=" slds-text-link">{!qli.Name}</a></td>
                            <td>
                                <div class="slds-text-title slds-text-color_default">Completed</div>
                            </td>
                            <aura:iteration items="{!v.planNames}" var="plan">
                                <aura:if isTrue="{!v.selectedPlanValue == plan}">
                                    <td>
                                        <div class="slds-text-title slds-text-color_default">${!qli.planMap[plan]}*</div>
                                    </td>
                                </aura:if>                                        
                            </aura:iteration>
                            <td>
                                <div class="slds-text-title slds-text-color_default">Completed</div>
                            </td>
                        </tr>
                    </aura:iteration>

quoteLinteItems -- is a List of Json objects

  • can you please show where you are fetching: ${!qli.planMap[plan]}* values...Remove $ and try it – SFDC FAN Jul 3 at 11:12
  • 1
    Please include the exact error message in your post verbatim via edit. – Adrian Larson Jul 3 at 11:14
  • added controller logic and json and error message.. now I am returning a wrapper class object from apex. – mvk1991 Jul 3 at 11:25
  • Do some null check .If it contains values then only try to access it – SFDC FAN Jul 3 at 11:30
  • I am getting this as a compile error – mvk1991 Jul 3 at 11:31
0

You can find some difficulties while using the JSON object into aura:iteration. You have to parse into a list and then use it aura iteration

Let me assume your use case is when the component initializes the table will generate,

then take an attribute:

<aura:attribute name="testList" type="List" default="{}"/>

on initializing the JS controller will be:

var jsonList = component.get("v.planNames");
var results=[];
for(number i=0;i<jsonList.length;i++){
   results.push(jsonList[i].your_property_name); 
}
component.set("v.testList", results);

Now you can replace the 'planNames' attribute with 'testList'.

That's all. Now you are ready to go. Hope your problem resolves.

  • It's a json object already. – mvk1991 Jul 3 at 11:28
  • Just updated the code. Please check if this resolves your problem – Sourav_Saha__x Jul 3 at 15:19
  • Thanks Sourav.. but I think add unnecessaary columns.. see I had a check to prevent that.. <aura:if isTrue="{!v.selectedPlanValue == plan}"> .. I thought of your wat of code this.but I don't think it works.. is there any way I can dynamically get the value based on the selected value..{!qli.planMap["{!v.selectedPlanValue }"]} – mvk1991 Jul 3 at 15:31
  • From where did you get the {!v.selectedPlanValue}? – Sourav_Saha__x Jul 3 at 15:37
  • It is an attribute, It is getting from lightning:combobox – mvk1991 Jul 3 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.