所以我正在用剃刀编写此应用程序,现在我正在做一个自定义导航栏。现在,问题出在我编写的OnInitialized
事件中:
protected async override void OnInitialized()
{
base.OnInitialized();
var user = (await AuthStat).User;
if (user.Identity.IsAuthenticated)
{
await Authenticated();
}
else
{
await NotAuthenticated();
}
}
其中的功能是:
protected Task Authenticated()
{
treedata = null;
treedata = new List<TreeData>();
treedata.Add(new TreeData { nodeId = "01", nodeText = "Acasa", iconCss = "icon-microchip icon" });
treedata.Add(new TreeData { nodeId = "03", nodeText = "Logout", iconCss = "icon-thumbs-up-alt icon" });
treedata.Add(new TreeData { nodeId = "04", nodeText = "Vremea", iconCss = "icon-th icon" });
treedata.Add(new TreeData { nodeId = "05", nodeText = "Profil", iconCss = "icon-code icon" });
treedata.Add(new TreeData { nodeId = "06", nodeText = "Calcul Salariu", iconCss = "icon-chrome icon" });
treedata.Add(new TreeData { nodeId = "07", nodeText = "Mijloace Fixe", iconCss = "icon-up-hand icon" });
return Task.CompletedTask;
}
protected Task NotAuthenticated()
{
treedata = null;
treedata = new List<TreeData>();
treedata.Add(new TreeData { nodeId = "01", nodeText = "Acasa", iconCss = "icon-microchip icon" });
treedata.Add(new TreeData { nodeId = "02", nodeText = "Login", iconCss = "icon-docs icon" });
treedata.Add(new TreeData { nodeId = "04", nodeText = "Vremea", iconCss = "icon-th icon" });
treedata.Add(new TreeData { nodeId = "06", nodeText = "Calcul Salariu", iconCss = "icon-chrome icon" });
return Task.CompletedTask;
}
变量treedata
为:
SfTreeView<TreeData> TreeView;
public class TreeData
{
public string nodeId { get; set; }
public string nodeText { get; set; }
public string iconCss { get; set; }
public bool hasChild { get; set; }
public string pid { get; set; }
}
我的问题如下:每当页面加载时,treedata仅在发生操作(即搜索或切换导航菜单)时填充,并且我想在页面加载时显示,但我不知道如何
答案 0 :(得分:2)
//protected async override void OnInitialized()
protected override async Task OnInitializedAsync()
{
// base.OnInitialized();
// ... like before
尚未(无法)等待async void
方法。您的Authenticated / NotAuthenticated方法与渲染不同步。
答案 1 :(得分:1)
我们检查了您的附加代码,发现您已经使用await方法来获取用户名和TreeView数据源。此函数需要一些时间来获取TreeView组件的用户名和数据源。 TreeView组件不会等到从该函数获取数据后才使用空数据源进行呈现。这是您报告的问题的原因。
我们已经将此问题视为要在TreeView组件中实现的功能支持。该功能的支持将包含在我们的第3卷版本中,该版本预计在2020年9月结束时推出。
感谢您的耐心等候。
关于, 小宫P