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.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
Each instance of foreach will have its own index separate from the one it is being called within.
Every attempt I have had at referencing the outermost index always end up duplicating the inermost index an resulting in a gid like.
ie trying to lable coords of a grid as xy, where x is the outermost index and y is the innermost
goal matrix
00, 01, 02, 03
10, 11, 12, 13
20, 21, 22, 23
actual result matrix
00, 11, 22, 33
00, 11, 22, 33
00, 11, 22, 33
Is there a way to access the parent index in a nested foreach?
Beta Was this translation helpful? Give feedback.
All reactions