Results 1 to 5 of 5

Thread: Setting up and looping through a 3D array?

  1. #1
    Join Date
    Jul 2008
    Posts
    22
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Setting up and looping through a 3D array?

    Hi,

    I'm banging my head off a brick wall with setting up a 3 dimensional array and trying to loop through it. I'm using the EJS framework (http://embeddedjs.com/).

    We currently have a 2D array set up to list out features. See below:

    topfeatures: [
    "Feature 1",
    "Feature 2",
    "Feature 3",
    "Feature 4",
    "Feature 5",
    "Feature 6"
    ]


    <ul>
    [% for(var i = 0; i < this.topfeatures.length; i++) { %]
    <li>[%= this.topfeatures[i] %]</li>
    [% } %]
    </ul>


    However, the request we have requires headlines for each set of features.

    Headline 1
    Feature1
    Feature2
    Feature3

    Headline 2
    Feature4
    Feature5
    Feature6


    Any ideas how I can do this?

  2. The Following User Says Thank You to denhamd2 For This Useful Post:

    round (05-22-2012)

  3. #2
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    What language aare you writing this is? PHP, ASP.NET? It's unclear from your post.

    EDIT: Just read the embedded Javascript thing. Looks good, but would play havok with ASP.NET. I'll have a look at this some more.

  4. #3
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    The best way to do it is to set up an object, then make an array of the objects.

    PHP Code:
    function oCatagory(titlefeatures) {

        
    this.Title title;
        
    this.Features = function() {
            var 
    aReturn = new Array();
            for(var 
    0features.lengthi++) {
                
    aReturn.push(features[i]);
            }
            return 
    aReturn;
        }
    }

    var 
    FeatureArray = new Array();
    var 
    aLangs = ['PHP''ASP.NET''SSI'];

    FeatureArray[0] = new oCatagory("Languages"aLangs);
    FeatureArray[1] = new oCatagory("Search Engines", ['Yahoo''Google''Ask']); 
    Then to output...

    Code:
    <% for(var i = 0; i < FeatureArray.length; i++) { %>
        <h2><%= FeatureArray[i].Title %></h2>
        <ul>
            <% for(var j = 0; j < FeatureArray[i].Features.length; j++) { %>
                <li><%= FeatureArray[i].Features[j] %></li>
            <% } %>
        </ul>
    <% } %>

  5. #4
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    That should output:

    Languages
    • PHP
    • ASP.NET
    • SSI


    Search Engines
    • Yahoo
    • Google
    • Ask

  6. #5
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    As a matter of interest, has anyone tried this EJS Embedded JavaScript Framework in conjuction with ASP.NET? Would it even work?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •