[ENG-4570] Iterate over ObjectVar.entries
This commit is contained in:
parent
27a745b38d
commit
9f83b654d7
@ -60,7 +60,7 @@
|
|||||||
{# Args: #}
|
{# Args: #}
|
||||||
{# component: component dictionary #}
|
{# component: component dictionary #}
|
||||||
{% macro render_iterable_tag(component) %}
|
{% macro render_iterable_tag(component) %}
|
||||||
<>{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
|
<>{ {{ component.iterable_state }}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
|
||||||
{% for child in component.children %}
|
{% for child in component.children %}
|
||||||
{{ render(child) }}
|
{{ render(child) }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -54,6 +54,8 @@ class Foreach(Component):
|
|||||||
TypeError: If the render function is a ComponentState.
|
TypeError: If the render function is a ComponentState.
|
||||||
UntypedVarError: If the iterable is of type Any without a type annotation.
|
UntypedVarError: If the iterable is of type Any without a type annotation.
|
||||||
"""
|
"""
|
||||||
|
from reflex.vars.object import ObjectVar
|
||||||
|
|
||||||
iterable = LiteralVar.create(iterable)
|
iterable = LiteralVar.create(iterable)
|
||||||
if iterable._var_type == Any:
|
if iterable._var_type == Any:
|
||||||
raise ForeachVarError(
|
raise ForeachVarError(
|
||||||
@ -70,6 +72,9 @@ class Foreach(Component):
|
|||||||
"Using a ComponentState as `render_fn` inside `rx.foreach` is not supported yet."
|
"Using a ComponentState as `render_fn` inside `rx.foreach` is not supported yet."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if isinstance(iterable, ObjectVar):
|
||||||
|
iterable = iterable.entries()
|
||||||
|
|
||||||
component = cls(
|
component = cls(
|
||||||
iterable=iterable,
|
iterable=iterable,
|
||||||
render_fn=render_fn,
|
render_fn=render_fn,
|
||||||
|
Loading…
Reference in New Issue
Block a user