-
|
I feel like there should be a simple solution to this that I am overlooking, or I am going about this in the wrong way. When working with foreach component, you can pass an index along with the list for the function second argument. ie trying to lable coords of a grid as xy, where x is the outermost index and y is the innermost actual result matrix Is there a way to access the parent index in a nested foreach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@QGoos try something like this import pynecone as pc
class State(pc.State):
"""The app state."""
x: list[int] = [0, 1, 2]
y: list[int] = [0, 1, 2]
def index() -> pc.Component:
return pc.vstack(
pc.foreach(
State.x,
lambda x: pc.hstack(
pc.foreach(
State.y,
lambda y: pc.text(x, y),
),
),
)
)
# Add state and page to the app.
app = pc.App(state=State)
app.add_page(index)
app.compile()
|
Beta Was this translation helpful? Give feedback.

@QGoos try something like this