【发布时间】:2021-12-07 21:38:34
【问题描述】:
我有一个编辑表单,里面有多个 MudTabPanel。 问题是,我有很多此类的属性,我们决定分成多个面板,每个面板都包含一个具有不同表单/输入的编辑表单。
格式有点像这样(伪剃须刀代码):
<MudTabs>
<MudTabPanel Text="Section 1">
<EditForm>
<MudItem>
<EditField Property1>
<EditField Property2>
...
<EditField Property 10>
</EditForm>
</MudTabPanel>
<MudTabPanel Text="Section 2">
<EditForm>
<MudItem>
<EditField Propertyn11>
<EditField Propertyn12>
...
<EditField Property 20>
</EditForm>
</MudTabPanel>
..... lots of other panels here
<MudTabPanel Text="Section N">
<EditForm>
<MudItem>
<EditField Property98>
<EditField Property99>
...
<EditField Property100>
</EditForm>
</MudTabPanel>
</MudTabs>
问题是: 在这个剃须刀页面中,我有 +1000 行代码! VS 2022 Preview 正在努力为我提供不错的性能(在 UI 上似乎工作正常),但在 VS 中只修改一个属性是一件很痛苦的事情。
我正在考虑将每个面板移动到一个单独的组件中,并将我的实体作为参数传输。
但是: 1).现在,因为我将所有这些都用于单页剃须刀,所以在代码页上,假设我有方法 DoSomething(),我可以在每个面板上使用此方法。 如果我要拆分它们,我是否需要在每个组件上重复 DoSomething() ?有没有办法可以分享这种方法? 2).你认为这会影响 UI 的性能吗? 3).有没有更好的方法?
LE:更新了我的数据绑定示例
后面的代码:
private Article _article;
我的第一个选项卡中的一些绑定示例:
<MudNumericField T="int?" @bind-value="_article.ArticleID">
<MudSelect @bind-Value="_article.UnitPriceIntervals" OffsetY="true" Label="Unit Price Interval" Variant="Variant.Outlined" Margin="Margin.Dense" Dense="true">
@foreach (UnitPriceIntervals? item in (UnitPriceIntervals[])Enum.GetValues(typeof(UnitPriceIntervals)))
{
<MudSelectItem Value="item">@item</MudSelectItem>
}
</MudSelect>
现在,我的文章属性还可以包含对存储在不同 SQL 表中的其他数据类型的引用,并且可以根据搜索更改它们。 示例:
_article.GeneralText1 = 1234
【问题讨论】:
标签: c# .net blazor webassembly mudblazor