Copied to clipboard

Flag this post as spam?

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


  • yumin 51 posts 243 karma points
    Dec 25, 2013 @ 03:10
    yumin
    0

    how to merger DynamicNode

    1.I get two dynamicNodes as the same doctype

    like this

    var newsCenter1 = homePage.newsCenter.First();

    var newsCenter2 = homePage.newsCenter.Last();

    how can i merger this to one?

    like

    var allNewsCenter = newsCenter1 + newsCenter2

    2.how to get position in foreach?

    3.how to end a method?

    like this

    @helper RenderNews(string ranges) {

    if(ranges == "")
    
    { return; }
    
    else
    
    { do something }
    

    }

    I try this but will get a exception and can't exit method

    thanks a lot 谢谢

  • Marcio Goularte 374 posts 1346 karma points
    Dec 26, 2013 @ 14:55
    Marcio Goularte
    1

    Hi Yumin,

    Try this:

    var newsCenter1 = homePage.newsCenter.First();

    var newsCenter2 = homePage.newsCenter.Last();

    var nodes = Model.NodeById(newsCenter1 .Id, newsCenter2.Id);

    foreach(var node in nodes){

    //Get Position

    @node.Position();

       }

     references:

    http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.aspx

    http://our.umbraco.org/documentation/Cheatsheets/DynamicNodeRazor.pdf

     

     

  • Charles Afford 1163 posts 1709 karma points
    Dec 26, 2013 @ 17:15
    Charles Afford
    0

    Marcio, Model.NodeById does not take 2 paramters does it?

    Yumin what are you trying to achieve?  Why are you trying to merge to Nodes?  If feels like you are doing something wrong.

     

    Charlie :)

  • Marcio Goularte 374 posts 1346 karma points
    Dec 26, 2013 @ 17:51
    Marcio Goularte
    100

    Sorry my mistake. Is NodesById method that takes as a parameter ids and not NodeById.

    Fixing:

    var newsCenter1 = homePage.newsCenter.First();

    var newsCenter2 = homePage.newsCenter.Last();

    var nodes = Model.NodesById(newsCenter1.Id, newsCenter2.Id);

    foreach(var node in nodes){

    //Get Position

    @node.Position();

       }

     

     

  • Charles Afford 1163 posts 1709 karma points
    Dec 27, 2013 @ 13:40
    Charles Afford
    0

    I still dont see the point in doing this?  And what version of umbraco are you using?

    If you want to get the children of a parent node just do a foreach around children of the parent

    foreach(Node contextNode in Node.children)

    {

    do work

    }

  • Marcio Goularte 374 posts 1346 karma points
    Dec 27, 2013 @ 14:10
    Marcio Goularte
    0

    I understood that yumin have more than one NewsCenter document type and want to display the first and last. Now it's wait and see if it is.

  • yumin 51 posts 243 karma points
    Dec 30, 2013 @ 02:44
    yumin
    0

    thanks for all reply, my site use for group has 13 branch companies,each has a newsCenter, and some high level(like ceo or cto etc.) need to read 2 or more newsCenter, so I have to merger this newsCenter to one, then I can sort or do something paging or first news has first css, if not merger to one , when I do paging or get first or last will get wrong Position(), like this:

    newsCenter1
      --news1    position=0
      --news2    posttion=1
    newsCenter2
      --news1    position=0
      --news2    posttion=1
    
    merger to one
    
    newsCenterAll
      --news1    position=0
      --news2    posttion=1
      --news3    position=2
      --news4    posttion=3
    

    so i can do anything i want, this why i want merger , i don't know if has a better way solve the problem

    hope you can understand, I did't learn english well because the teacher is not pretty ^_^

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 30, 2013 @ 10:31
    Fuji Kusaka
    0

    Hi there,

    Has this threat been solved ?

    In your loop you can do something like

    foreach(var node in nodes){
    if(node.IsFirst()){
    }
    if(node.IsLast()){
    }
    }

    May be this wil help you http://our.umbraco.org/documentation/Reference/Querying/DynamicNode/IsHelpers

     

  • yumin 51 posts 243 karma points
    Dec 31, 2013 @ 02:45
    yumin
    0

    hi fuji,

    foreach(var newsCenter in newsCenters)
    {
        foreach(var news in newsCenter.Children)
       {
            if(news.IsFirst())
            {   Response.Write("first"); }
       }
    }
    

    you will get two "first", why? because newsCenter1's news1.IsFirst() == true and newsCenter2's news1.IsFirst() == true, so why i must merger two newsCenter to one nodes

  • yumin 51 posts 243 karma points
    Dec 31, 2013 @ 02:50
    yumin
    0

    marcio's method can solve this problem

    var nodes = Model.NodesById(newsCenter1.Id, newsCenter2.Id);
    

    thanks very much

    and anybody knows how to end a method use return?

    I tried to code like this but not use

    if(aa == false)
    {
       return;
    }
    

    it will get a exception

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 31, 2013 @ 06:15
    Fuji Kusaka
    0

    Can you please show what will be your end result in html ?

Please Sign in or register to post replies

Write your reply to:

Draft