0
我有這一塊,我試圖將轉換爲拉姆達碼 -綁定嵌套列表
foreach (var facet in response.Result.Facets)
{
var newFacet = new Facet {Parent = facet.Title};
foreach (var element in facet.Subelements)
{
newFacet.Items.Add(new Facet
{
Title = element.Title,
TotalResults = element.TotalResults
});
}
searchModel.Facets.Add(newFacet);
}
這裏是我迄今爲止 -
response.Result.Facets.ForEach(x => searchModel.Facets.Add(new Facet
{
Parent = x.Title,
Items = ???//x.Subelements.ForEach(y=>)
}));
而類 -
public class Facet
{
public Facet()
{
Items = new List<Facet>();
}
public string Parent { get; set; }
public List<Facet> Items { get; set; }
public int TotalResults { get; set; }
public string Title { get; set; }
}
public class SearchElement
{
public string Parent { get; set; }
public string Title { get; set; }
public int TotalResults { get; set; }
public IList<ESearchElement> Subelements { get; set; }
}
如何綁定List<SearchElement>
到List<Items>
由每個元件(標題= YT映射itle ..)所有在一個lambda表達式內的行?可能嗎?
謝謝,但這是LINQ。我們可以在Lambda中做同樣的事嗎? – tempid
@ user349308 - 我添加了一個lambda版本。 – Enigmativity