Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4244970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:46:42+00:00 2026-05-21T03:46:42+00:00

This is a JavaScript/Ajax webpage (also using jQuery). I have a nested structure I

  • 0

This is a JavaScript/Ajax webpage (also using jQuery).

I have a nested structure I need to display. After displaying a top level element, users can click on it, and see levels below it (dynamically generated).

I don’t want to pre-generate everything and hide it with display: none (the page is complex, I’m simplifying for this question) – I want to build the display from the javascript array that was fetched with ajax.

My question:

I have two options:

1: Create a flat array:

[ {id: xx, children: [ xx, xx, .. ] }, ....]

Then for the onclick of an element I get the id from the array, find the children, pull them up from the array and display them. (I guess I’ll have to search through the array, since there are no associative arrays in javascript – or make an index.)

2: Create a nested array:

{ id: xx, children [ { id: xx, children : [....] }, {....} ] }

Then somehow bind the children in the array to the element when I display it.

I have two problems with this second approach:

A: I’m constantly copying large chunks of the array for each child when I create it. (At least I think I am. Do I need to use deep copy? Can I make a reference?)

B: I’m not sure how to bind the data to the child element. Normally I build the display using html strings with onClicks, then append the entire thing. But onClicks can only take an ID, not a copy of an array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:46:42+00:00Added an answer on May 21, 2026 at 3:46 am

    I did something similar recently where I had a very large nested structure (over 2000 nodes) – which I did not want to bulk append to the DOM.

    What I ended up doing was taking the ajax loaded data and converting it into a nested structure…

    <node id="1" title="a">
      <node id="2" title="b />
      <node id="3" title="b">
          <node id="4" title="d" />
      </node>
    </node> etc...
    

    …and storing this as a jQuery object (nodes), but never appending it to the DOM.

    I could then select the immediate children of a node as I needed them relatively easily, for converting into html elements and appending to the DOM, adding data, etc…

    $("#"+ID+">node", nodes).each(function() { 
        var node = $(this);
        //do whatever... 
    });
    

    I don’t know if this is the most memory-efficient approach, but it certainly makes it very easy to select and append the immediate children of a node to the DOM as you need them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js></script> <script type=text/javascript> function bigtosmalltriangle() { $(this).siblings(div.break).removeClass('triangle3').addClass('triangle1'); setTimeout ( smalltomediumtriangle(), 400 ); }
I have this bit of javascript written with jQuery 1.2.5. It's contained inside the
I'm running an AJAX request from a JavaScript-powered (+jQuery) webpage every 5 seconds for
I have this Javascript data: [{id:123,type:test},{id:154,type:another}] How would you transform that into something so
I already started this in javascript so I don't want to use jquery but
I have this piece of Javascript and it just won't work. I allready checked
I have this line of JavaScript and the behavior I am seeing is that
I have the following script element in my web page: <script src=default.js type=text/javascript></script> Using
I have a webpage that has JavaScript in it. The script contains a method
I have an javascript that I place into a page using the code below.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.