Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fredrik 89 posts 108 karma points
    Oct 28, 2010 @ 14:20
    Fredrik
    0

    Would this use of nodefactory work?

    I have a contentstructure like following example:

     

    Product(ID 1079)

         Product category1

                 Product category level2

                         Product category level3

                                Product

                         Product category level3

                                Product

                                Product

                  Product category level2

                          Product

     

    Would following code work to loop through the node-hierarchy and collect the nodes of type Product?

    [System.Web.Services.WebMethod]
            public static string[] GetNames(string prefixText)
            {
                List<String> namn = new List<String>();
                Node node = new umbraco.presentation.nodeFactory.Node(1079);
                foreach (Node child in node.Children)
                {
                    if (child.NodeTypeAlias == "Product")
                    {
                        namn.Add(child.Name);
                    }
                   
                    foreach (Node child2 in child.Children)
                    {
                        if (child.NodeTypeAlias == "Product")
                        {
                            namn.Add(child2.Name);
                        }
                       
                        foreach (Node child3 in child.Children)
                        {
                            if (child.NodeTypeAlias == "Product")
                            {
                                namn.Add(child3.Name);
                            }
                           
                            foreach (Node child4 in child.Children)
                            {
                                if (child.NodeTypeAlias == "Product")
                                {
                                    namn.Add(child4.Name);
                                }

                            }
                        }
                    }
                   
                }
                return namn.ToArray();
            }

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 28, 2010 @ 14:27
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Oct 28, 2010 @ 15:34
    Ismail Mayat
    0

    Frederik,

    You could even make an examine search for type product that would be even quicker.

    Regards

    Ismail

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 28, 2010 @ 23:12
    Aaron Powell
    0

    Why not go with a recursive function, that'd be a lot more logical than nested loops on top of nested loops

  • Fredrik 89 posts 108 karma points
    Oct 29, 2010 @ 10:51
    Fredrik
    0

    Thanks for the insightful input, things are working properly,

Please Sign in or register to post replies

Write your reply to:

Draft