如何捕获EditForm组件是否为;肮脏的;在Blazor webassembly中
Blazor Webassembly中是否有一个与Angular for EditForm中脏表单的概念相同的概念?我想显示一个文本“您已进行了更改。任何未保存的更改都将丢失!”以指示用户某些内容尚未保存,在离开前应点击提交按钮 是的,有,但我们不使用脏话,我们使用修饰或未修饰 EditContext类提供以下内容:如何捕获EditForm组件是否为;肮脏的;在Blazor webassembly中,blazor,blazor-client-side,Blazor,Blazor Client Side,Blazor Webassembly中是否有一个与Angular for EditForm中脏表单的概念相同的概念?我想显示一个文本“您已进行了更改。任何未保存的更改都将丢失!”以指示用户某些内容尚未保存,在离开前应点击提交按钮 是的,有,但我们不使用脏话,我们使用修饰或未修饰 EditContext类提供以下内容: /// <summary> /// Determines whether any of the fields in this <see
/// <summary>
/// Determines whether any of the fields in this <see cref="EditContext"/> have been modified.
/// </summary>
/// <returns>True if any of the fields in this <see cref="EditContext"/> have been modified; otherwise false.</returns>
public bool IsModified()
{
// If necessary, we could consider caching the overall "is modified" state and only recomputing
// when there's a call to NotifyFieldModified/NotifyFieldUnmodified
foreach (var state in _fieldStates)
{
if (state.Value.IsModified)
{
return true;
}
}
return false;
}
/// <summary>
/// Determines whether the specified fields in this <see cref="EditContext"/> has been modified.
/// </summary>
/// <returns>True if the field has been modified; otherwise false.</returns>
public bool IsModified(in FieldIdentifier fieldIdentifier)
=> _fieldStates.TryGetValue(fieldIdentifier, out var state)
? state.IsModified
: false;
/// <summary>
/// Determines whether the specified fields in this <see cref="EditContext"/> has been modified.
/// </summary>
/// <param name="accessor">Identifies the field whose current validation messages should be returned.</param>
/// <returns>True if the field has been modified; otherwise false.</returns>
public bool IsModified(Expression<Func<object>> accessor)
=> IsModified(FieldIdentifier.Create(accessor));
//
///确定此字段中的任何字段是否已修改。
///
///如果此字段中的任何字段已修改,则为True;否则就错了。
公共布尔值已修改()
{
如果需要的话,我们可以考虑缓存整个“被修改”的状态,只重新计算。
//当调用NotifyFieldModified/NotifyFieldUnmodified时
foreach(变量状态在_fieldStates中)
{
if(state.Value.IsModified)
{
返回true;
}
}
返回false;
}
///
///确定此字段中的指定字段是否已修改。
///
///如果字段已修改,则为True;否则就错了。
公共布尔值已修改(字段标识符字段标识符中)
=>\u fieldStates.TryGetValue(字段标识符,输出变量状态)
? state.IsModified
:假;
///
///确定此字段中的指定字段是否已修改。
///
///标识应返回其当前验证消息的字段。
///如果字段已修改,则为True;否则就错了。
公共bool已修改(表达式访问器)
=>IsModified(FieldIdentifier.Create(accessor));
这个问题还有一个方面-执行更新后如何重置IsModified标志?