<model> 如果 UI 中有任何更改,请更新列表项



如果不展示完整的概念,这有点难以解释,但我会尝试的。我有Record.razor.csthis.PersonellData的员工表。我正在通过以下方法将新员工添加到表中:

private void AddNew()
{
this.PersonellData.Add(new Personell
{
Id = i + 1,
Name = "John " + i,
From = DateTime.Today + new TimeSpan(8, 30, 0),
Category = this.selectedCategoryValue,
});
this.DiaryRecord.Employees = new List<Personell>(this.PersonellData);
i++;
}

然而,在添加员工后,我想在UI中更改类别和(起始(时间。我可以在UI中完成,但List<model>本身的数据不会发生变化。我在上设置了断点

private async Task OnCreateNewDiaryRecord()
{
if (true)
{
this.DiaryRecordModel = new DiaryRecord
{
Id = this.DiaryRecordModel.Id,
Title = this.DiaryRecordModel.Title,
Description = this.DiaryRecordModel.Description,
Employees = this.DiaryRecordModel.Employees,
Date = this.SelectedDate,
};
await OnInitializedAsync();
}
isDialogVisible = false;
}

在Index.razor.cs中,我在UI中对列表中的每个员工都没有做任何更改。有什么建议可以让它发挥作用吗?我应该为每个UI项添加像OnChange这样的方法吗?但如何继续更新实际列表?

这是日记记录.cs:

public class DiaryRecord
{
public Guid Id { get; set; }
public string Title { get; set; }
public ICollection<Personell> Employees { get; set; }
}

这是列表项的UI部分

<Table DataSource="this.PersonellData" RowClassName="@(_=>"editable-row")" Bordered Size=@TableSize.Small>
<Column Title="From" TData="DateTime">
<TimePicker TValue="DateTime?" @bind-Value="@context.From" OnChange="this.OnDateValueChanged" />
</Column>
<Column Title="Category" DataIndex="@nameof(context.Category)" TData="string">
<Select DataSource="@this.CategoryList"
@bind-Value="@this.selectedCategoryValue"
LabelName="@nameof(Category.CategorySymbol)"
ValueName="@nameof(Category.CategorySymbol)"
DefaultActiveFirstItem="false"
EnableSearch
OnSelectedItemChanged="this.OnSelectedCategoryChangedHandler">
</Select>
</Column>
</Table>

我试过使用OnChange="this.OnDateValueChanged",但不知道如何继续。

不要从自己的代码中调用OnInitializedAsync((。当你这样做时,它不会触发UI更新。
//await OnInitializedAsync();
await InvokeAsync(StateHasChanged);  // Invoke probably not needed. Just in case.

相关内容

  • 没有找到相关文章