Your sample only work's if the List is allready populated before first render.
If i add items to the List later the line (i had to use round brackets to post the Line...):
is skipped and no Chip is added. You directly can see this beahviour if you set a breakpoint on @foreach.
Any other Markup placed in the foreach-Block (for example: (span)@currentData.text(/span)) would be reached and executed. only the ChipListChip ist ignored.
Here's the Code to prove (round brackets just here to be able to post the Code):
@page "/"
@using Syncfusion.EJ2.Blazor.Buttons
(p)(/p)
(div)
(button @onclick="ClickButton")Hinzufügen(/button)
(/div)
(p)(/p)
(EjsChipList EnableDelete="true")
(ChipCollection)
@foreach(ChipCollection currentData in ChipData){
(span)@currentData.text(/span)
(ChipListChip
[email protected] [email protected])(/ChipListChip)
}
(/ChipCollection)
(ChipListEvents OnDelete="@OnDelete")(/ChipListEvents)
(/EjsChipList)
(div)Last Deleted Item: @DeleteItems(/div)
@code{
public List(ChipCollection) ChipData = new List(ChipCollection)();
public string DeleteItems { get; set; }
public class ChipCollection
{
public string text { get; set; }
public bool enabled { get; set; }
}
protected override void OnInitialized()
{
base.OnInitialized();
ChipData.Add(new ChipCollection
{
text = "Jenifer",
enabled = true
});
ChipData.Add(new ChipCollection
{
text = "Amenda",
enabled = true
});
ChipData.Add(new ChipCollection
{
text = "Isabella",
enabled = true
});
ChipData.Add(new ChipCollection
{
text = "James",
enabled = true
});
}
public void OnDelete(DeleteEventArgs args)
{
DeleteItems = args.Text;
}
public void ClickButton()
{
ChipData.Add(new ChipCollection
{
text = "Name"+DateTime.Now.Ticks.ToString(),
enabled = true
});
}
}