Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Looping, Closures and Binding

$
0
0

I broke this down to a simple example of Looping through some stuff but breaking it out in levels. I'm instantiating a local copy in the inner loop but that doesn't seem to work.When you try and change a value in the input it changes them all to the counter variable.

Here's the code in Blazor Fiddlehttps://blazorfiddle.com/s/d02wswws

@for (var i = 0; i < levels; i++){<div>Level @i</div>    @for (var j = 0; j < stuffPerLevel; j++)                {        int copy = allStuffCounter;<input type="text" @bind="stuff[copy]" @bind:event="oninput" /><div>@stuff[copy]</div>        if(allStuffCounter < stuffCounterLimit) allStuffCounter++;    }}@code{  string[] stuff = {"some stuff 1", ... ,"some stuff 20"};  int allStuffCounter = 0;  int levels = 3;  int stuffPerLevel = 4;  int stuffCounterLimit = 11;}

Viewing all articles
Browse latest Browse all 4839

Trending Articles