Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 26, 2013 @ 22:31
    Fuji Kusaka
    0

    Getting xth value from a multiNodeTree Picker

    Can someone please tell me how do i retrieve the xth value from a multiNodeTree Picker.

    For some reason i need to display xth of an image within a div where both xth values should be displayed differently,

    Here is my razor code

    var figures = @CurrentModel.GetProperty("ke").Value.ToString();
            string[] ids = figures.Split(',');
           
           
           
            var count = 0;
            
                     
                      @foreach(string id in ids){
                          count ++;
                          var node = Library.MediaById(id);
                         
                         
                          if(id.Any()){
                             
                              if(node.IsFirst()){
                                      @node.Name

                                  }
                             
       
                         else{
                                  @node // Here i wold like display 10 th value
                              }
                             
                              if(count.IsLast()){
                                  @node.Url
                                   @:  @count

                              }
                             
                          }
                         
                         
                      }

               
          
             
        }

    Any suggestions please ?

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Jul 26, 2013 @ 23:13
    Anders Bjerner
    0

    Since I don't know your tree structure, I'm not sure whether I can help, but try having a look at this:

    A small change for splitting the string. The extra parameter will make sure empy entries are removed. This will also mean, that if the string is empty, you will now have an empty array rather than an array with an empty string.

    string[] ids = figures.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries)

     You can now loop through the ids with a for loop:

    for (int i = 0; i < ids.Length; i++) {

    var node = Library.MediaById(ids[i]);

    if (i == 0) {
    // first node
    } else if (i == 9) {
    // 10th node
    } else if (i == ids.Length - 1) {
    // last node
    } else {
    // all other nodes
    }

    }
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 27, 2013 @ 05:50
    Fuji Kusaka
    0

    Hi Anders,

    Thanks for the input but not really what am looking for. For the record am using the multiTreeNode picker to on a docType where user will be able to get display certain images on current node.

    Having said that the first and last image will always be in their respective div container. However the 2nd and 3rd are both in the same container within another div container.

    So for the 2nd and 3rd i was thinking of displayin them by doing something more like

    else {
    <div>
     <div>@node.[3]</div>
    <div>@node.[2]</div>
    </div>
    }

    But this aint working.

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 27, 2013 @ 09:45
    Jeavon Leopold
    0

    Hi Fuji,

    I would use the code sample from here to get a collection and then just use the normal .Skip(2) method.

    thanks,

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 27, 2013 @ 11:47
    Fuji Kusaka
    0

    Hi Jeavon,

    Did that as well but still not working

    IEnumerable<Media> Folder = Library.MediaById(CurrentModel.GetProperty("keyFigures").Value.ToString().Split(','));
  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 27, 2013 @ 20:27
    Fuji Kusaka
    0

    So far this is working but here where i need to display not the prettiest wat of doing things but working

    if(i == 0){
                            @node.Url <br/>
                    }
                   
                    else if (i == ids.Length - 1) {
                        @node.Url <br/>
                    }
                    else{
                        <div class="ot-d">
                            @if(i == 1){
                                <div class="2nd">
                                    @node.Name
                                </div>
                            }
                            @if(i == 2){
                                <div class="3nd">
                                    @node.Name
                               </div>
                            }
                        </div>
                           
                    }

     

    If someone has a better way, please do let know

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 27, 2013 @ 21:24
    Jeavon Leopold
    0

    Hey Fuji,

    So jsut to be clear, you have a MNTP picking media and storing as CSV and you want to be able to retreive certain items based on position within MNTP?

    Thanks,

    Jeavon

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 27, 2013 @ 22:31
    Jeavon Leopold
    0

    I was thinking something like this:

        if (Model.HasValue("mntpMediaPickerCSV"))
        {
            List<int> mediaIdList = ((string)Model.mntpMediaPickerCSV).Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
            dynamic mediaList = Library.MediaById(mediaIdList);                 
            <p>@mediaList.Skip(2).First().Name</p> 
        } 

     But it might not be the right approach...

  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Jul 27, 2013 @ 22:44
    Anders Bjerner
    1

    Let assume you have the images 1, 2, 3, 4 and 5. Should they be displayed something like this?

    <div>nr1</div>
    <div>
        <div>nr2</div>
        <div>nr3</div>
    </div> 
    <div>nr5</div>

     If that is the case, the code can look something like this:

    if (ids.Length >= 4) {
    
      var nr1 = Library.MediaById(ids[0]);
      var nr2 = Library.MediaById(ids[1]);
      var nr3 = Library.MediaById(ids[2]);
      var last = Library.MediaById(ids[ids.Length - 1]);
    
      <div>@nr1</div>
      <div>
        <div>@nr2</div>
        <div>@nr3</div>
      </div>
      <div>@last</div>
    
    } else {
      // less than four items in total - do something else
    }
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jul 27, 2013 @ 23:16
    Jeavon Leopold
    0

    Looks good Anders!

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 29, 2013 @ 08:16
    Fuji Kusaka
    0

    Hi Guys,

    Thanks for the inpu. @Anders, when using your, method i get the duplicate values since the div is within the same inner div. First and Last has there own div container and 2nd and 3rd are within a div container but with their own div container again. :)

    This works for me atm.

    if(i == 0){
        @node.Url <br/>
    }
    else if (i == ids.Length - 1) {
        @node.Url <br/>
    }
    else{
                        var nr2 = Library.MediaById(ids[1]); //Second MediaItem
                        var nr3 = Library.MediaById(ids[2]);                // Third MediaItem
    <div class="ot-d">
           @if(i == 1){
    <div class="2nd">
               @nr2.Url
    </div>
                                 }
    @if(i == 2){
    <div class="3nd">
    @nr3.Url
      </div>
    }
    </div>
    }
  • Anders Bjerner 487 posts 2989 karma points MVP 8x admin c-trib
    Jul 29, 2013 @ 20:35
    Anders Bjerner
    0

    Hi Fuji,

    I you can describe how the HTML should look in various scenarios, I might be able to help you clean up your code a bit ;) Currently it seems you're using a loop of some kind - which as far as I have understood your problem - isn't the optimal solution.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 29, 2013 @ 20:41
    Fuji Kusaka
    0

    Hi Anders,

    Well it turns out since am using Mansonry Query to get some better results for responsive layouts the 3rd and 4th value gets a bit mess up in turns of positioning the div elements. :)

    But so far everything is working as should will some "Ifs" !

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 29, 2013 @ 20:49
    Fuji Kusaka
    0

    This is how my code looks like atm

     if (i == 0){
                                <div class="box col1 fondOrange">
                                  <div class="cnInner"> <img src="@node.Url" /><span class="currency helTh">Rs</span> <span class="amount helTh"><strong>20.5</strong> billion</span> <span class="helTh">of assets under management</span></div> 
                                </div>
                                }

                                if (i == 1){
                                    <div class="box colSmall">
                                        <div class="cnInner"> <img src="@node.Url" /> <span class="currency helTh">Rs</span> <span class="amount helTh"><strong>20.5</strong> billion</span> <span class="helTh">of assets under management</span> </div> 
                                    </div>
                                }

                                if (i == ids.Length - 2){   
                                       <div class="box col1 cnDebt">
                                           <div class="cnInner"> <img src="@node.Url" /> <span class="currency helTh">Rs</span> <span class="amount helTh"><strong>20.5</strong> billion</span> <span class="helTh">of assets under management</span></div> 
                                        </div>
                                }

                                if(i== 3){
                                   <div class="box colSmall">
                                    <div class="cnInner"> <img src="@node.Url" /> <span class="currency helTh">Rs</span> <span class="amount helTh"><strong>20.5</strong> billion</span> <span class="helTh">of assets under management</span></div> 
                                   </div>
                                }
Please Sign in or register to post replies

Write your reply to:

Draft