0

I'm trying to access values in a custom JSON object more efficiently within Javascript, rather than iterating through it each time I need to update a value. Within JavaScript I can access each item easily using the unique identifier if I have the JSON structured like below.

The problem is I'm not sure on how to iterate over this type of JSON structure using the Aura:Iteratation element.

Has anyone else been able to successfully use the Aura:Iteration element over this type of JSON structure?

{
"YET-1234":
{
"carName" : "Buick",
"carModel": "Wagon,
"carYear" : "1832",
},
"UIJ-5434":
{
"carName" : "Ford",
"carModel": "Model-T
"carYear" : "2022",
}
}

1 Answer 1

2

Has anyone else been able to successfully use the Aura:Iteration element over this type of JSON structure?

No, nobody has been able to directly iterate over this, because that's impossible. You can only iterate over an Array. Fortunately, that's effortless in JavaScript:

let newArray = Object.entries(carModelObject);

This creates an Array that contains Arrays that have the key in the zeroth index, and the value (e.g. { carName: 'Buick', carModel: 'Wagon', carYear: '1832' }) in the first index.

Your iteration can then be:

<aura:iteration items="{!v.rows}" var="row">
  Model Name: {!row[0]}, 
  carName: {!row[1].carName}, 
  carModel: {!row[1].carModel}, 
  carYear: {!row[1].carYear}
</aura:iteration>

You must log in to answer this question.

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