我无法完成这项工作,我想要一个使用选择映射的组件但是如果孩子的类型与主要来源相同我不想再次映射选择那可能无限的,但如果它不同那么我必须在第一部分进行映射。这将在树视图组件中使用(在这种情况下,我们假设子类型与主要源相同;其他我们必须映射另一个选择)
ComponentUC.DataSource = SomeList.Select(t =>
new {
name = t.Title,
type = "folder",
additionalParameters = new { UId = t.UId },
data = t.Children
}
);
ComponentUC
public object DataSource;
protected void Page_Load(object sender, EventArgs e)
{
object Result = ((List<dynamic>)DataSource).Select(t => Rec(t)).ToJson();
}
public object Rec(dynamic item)
{
if (item.Children.Count != 0)
{
if (DataSource.GetType().GenericTypeArguments[DataSource.GetType().GenericTypeArguments.Count()] == item.Children.GetType())
item.Children = ((List<dynamic>)item.Children).Select(r => Rec(r));
return
new
{
name = item.name,
type = item.type,
additionalParameters = item.additionalParameters,
data = item.Children
};
}
else
{
return
new
{
name = item.name,
type = item.type,
additionalParameters = item.additionalParameters
};
}
}