0

We have data as below in track variable rowColorRules :

[{
    "color": "#ED0E0E",
    "criterias": [{
        "field": "sdd",
        "operator": "==",
        "value": "asdads"
    },{
        "field": "sdd",
        "operator": "==",
        "value": "asdads"
    }],
    "upArrow": false,
    "downArrow": false
}]

So, here rowColorRules is array and criterias within each rowColorRules is also array and we are trying to iterate nested for:each withing main for:each But in for:each of criterias we are getting below errors:

enter image description here

HTML code is as below:

<template for:each={rowColorRules} for:item="rule" for:index="index">
    <!-- some html -->
    <template for:each={rule.criterias} for:item="criteria">
        <!-- some html -->
    </template>
</template>

If i will remove for loop of criterias then it will start working perfectly.

2
  • It should not throw error - can you show full code? Commented Sep 3, 2019 at 8:39
  • You should have a key field that is unique for each iteration item. Commented Mar 31, 2021 at 8:07

1 Answer 1

0

Just tried from my end in LWC playground. I am not getting any error

@track test = [{
    "color": "#ED0E0E",
    "criterias": [{
        "field": "sdd",
        "operator": "==",
        "value": "asdads"
    },{
        "field": "sdd",
        "operator": "==",
        "value": "asdads"
    }],
    "upArrow": false,
    "downArrow": false
}]

    <template>
        <template for:each={test} for:item="rule" for:index="index"> 
            <template for:each={rule.criterias} for:item="criteria">
              {criteria.operator}
            </template>
        </template>
    </template>
1
  • Actually there are 2 component and this JSON is part of parent component and child is calling CustomEvent and passing some data to parent, parent will alter the JSON. After that It should refresh the view (html renderer). But i am getting the error. @learningmode It is working first time when component will load. Commented Sep 3, 2019 at 9:31

You must log in to answer this question.

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