-
-
Notifications
You must be signed in to change notification settings - Fork 998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Descriptions Component does not support dynamic Description collection #3326
Comments
I add a more interesting code to show the strange behavior: the status and the counter response all work, but the descriptions & description does not! @page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<Descriptions Title="User Info">
<DescriptionsItem Title="UserName">Zhou Maomao</DescriptionsItem>
<DescriptionsItem Title="Telephone">18100000000</DescriptionsItem>
<DescriptionsItem Title="Live">Hangzhou, Zhejiang</DescriptionsItem>
@if(showAdvance){
<DescriptionsItem Title="Remark">Empty</DescriptionsItem>
<DescriptionsItem Title="Address">
No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China
</DescriptionsItem>
}
</Descriptions>
<button @onclick="@(()=> { showAdvance = !showAdvance; currentCount++;})" >switch mode</button>
@currentCount <br/>
@showAdvance
@code {
private int currentCount = 0;
private bool showAdvance=false;
private void IncrementCount()
{
currentCount++;
}
} |
Fyi. The same problem: dotnet/aspnetcore#47218 as the descriptionitem add itself to parent items in initialization which is later after descriptions parent set parameters, it will have nochance to trigger parent’s preparematrix internal status, which make later render render old data? One solution is always prepare matrix before render? Another way is to use render fragments? |
I'm not sure if the render fragment will work, maybe it will reproduce the initialization logic when the render is refreshed. |
you are right, it does not work! error as before! @page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<Descriptions Title="@(currentCount.ToString())">
@GenDescriptions()
</Descriptions>
<button @onclick="@(()=> { showAdvance = !showAdvance; currentCount++;})" >switch mode</button>
@currentCount <br/>
@showAdvance
@code {
private int currentCount = 0;
RenderFragment GenDescriptions() => @<text><DescriptionsItem Title="UserName">Zhou Maomao</DescriptionsItem>
<DescriptionsItem Title="Telephone">18100000000</DescriptionsItem>
<DescriptionsItem Title="Live">Hangzhou, Zhejiang</DescriptionsItem>
@if (showAdvance)
{
<DescriptionsItem Title="Remark">Empty</DescriptionsItem>
<DescriptionsItem Title="Address">
No. 18, Wantang Road, Xihu District, Hangzhou, Zhejiang, China
</DescriptionsItem>
}</text>;
private bool showAdvance=false;
private void IncrementCount()
{
currentCount++;
}
} |
unless blazor provides something like OnBeforeRender/override StateChanged, there is no perfect solution, as the item init/dispose happens too later, which will cause Descriptions to use old items data. on another side, the preparematrix is really just something about render internal, not related to the logical part, call before StateChanged internal is perfect ref: |
Describe the bug
the dynamic collection does not work!
Steps to reproduce (please include code)
basic idea:
Exceptions (if any)
n.a
Further technical details
AntDesign v0.15.1
ref:
https://antblazor.com/zh-CN/components/descriptions
The text was updated successfully, but these errors were encountered: