可以从foreachLoop Umbraco c#中获取数据个体数据

Can get data individual data from foreachLoop Umbraco c#

我的代码工作正常,但是当我尝试获取每个基金的数据时 = subpage.Name 我得到的所有基金数据都不是单独的。我在这里缺少什么?? 谁能帮我?对不起,我是 umbraco 和 c# 的新手,管理这个的最佳方法是什么

现在是这样

(16) [{…}, {…},]...
0: {Fundo: "CURTO PRAZO", data: Array(21)}
1: {Fundo: "CA MONETARIO", data: Array(21)}
...

In reality it should be

(16) [{…}, {…},]...
0: {Fundo: "CURTO PRAZO", data: Array(4)}
1: {Fundo: "CA MONETARIO", data: Array(3)}
for example
...

这是我的代码

    var currentPage = Model.Content;

    var selection = Umbraco.Content(1448);

    @foreach (var page in selection.Children){

    if(page.Children.Count() > 0){ 

    foreach(var subpage in page.Children){

    var listaPdf = subpage.GetPropertyValue<IEnumerable<IPublishedContent>>("listaPdfsFundos");

         if(listaPdf == null) {

         listaPdf = new List<IPublishedContent>();}

        if(listaPdf != null){

        foreach(var row in listaPdf) {

        name = Umbraco.Field(row, "categoriaDoFundo").ToString();

        var id = Umbraco.Field(row, "documentos").ToString();

        var mediaItem = Umbraco.TypedMedia(id);

        url = mediaItem.Url;

        <script type="text/javascript">

       data.push({"Nome":"@name", "Url":"@url"}); 

        </script> 
         }

         <script type="text/javascript">

        list.push({"Fundo":"@subpage.Name", data }); 
        </script> 

              }

            }

        }

     }

您应该使用 UmbracoHelper 来获取 IPublishedContent,然后您可以获取内容页面的子项并访问各个属性。

详情请见下方;在我的示例中,我的测试内容 ID 是我主页的 nodeId,看看我如何获得主页的子项和第一个子项的属性 - 所以请根据此更新您的代码,有关更多详细信息,请使用 a look at this;

            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            var testContentId = 1353; // This is your umbraco node id of your content page
            var publishedContent = umbracoHelper.TypedContent(testContentId);

            if (publishedContent != null)
            {
                foreach (var child in publishedContent.Children)
                {
                    // This is where you can reach the Children of this child as well as individual properties of this child
                    if (child.HasProperty("emailAddress_Contact_Information"))
                    {
                        var emailAddressContactInformation = child.GetProperty("emailAddress_Contact_Information");
                    }
                }
            }