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 3632028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:28:24+00:00 2026-05-19T00:28:24+00:00

so I’ve been working on a project in Javascript that takes in objects the

  • 0

so I’ve been working on a project in Javascript that takes in objects the user provides and represents them in HTML. Right now they are represented in memory as an array, and in the display as a separate array. After integrating some code changes, problems have arisen in that the display array seems to be having troubles removing it’s contents, thus things that should be removed don’t disappear from the view.

Declaring lists:

this.divList = gDocument.getElementById( element );
this.objectList = []; 

Adding an object to the lists:

addObject = function (address, type){
    var newDiv = gDocument.createElement("div");
    this.divList.appendChild( newDiv );

    var d = this.createObject( newDiv, address, type );

    if (undefined != d)
    {
        this.objectList.push(d);
    }
 }

The divList accurately reflects the objectList until any changes are made to the objectList at runtime. When restarted, the lists are in sync once again. When I tried to fix it, things were very complicated. I’m wondering if there is a better way to design such an idea (the object model and the graphical representation). Any comments would be helpful, thanks.

  • 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-19T00:28:25+00:00Added an answer on May 19, 2026 at 12:28 am

    Question vagueness aside, my recommendation would be to store one list, not two, in memory. Each list element is an object with all the necessary data you need for that particular abstract “object” (the ones that “the user provides”). Something like this:

    this.divList = gDocument.getElementById(element);
    this.masterList = [];
    var i,
        len = this.divList.length;
    for (i = 0; i<len; i++)
    {
        this.masterList.push({
            elt: this.divList[i],
            obj: /* however you'd create the object in this.objectList  */
        });
    }
    

    Edit: your addObject function would be changed to something like this:

    addObject = function (address, type)
    {
        var newDiv = gDocument.createElement("div"),
            newObj = {elt: newDiv,
                      obj: this.createObject(newDiv, address, type)};
        this.masterList.push(newObj);
        this.divList.appendChild(newDiv);
     }
    

    You should store a reference to the HTML element that you’re appendChild()ing to. You’re already doing this – but when you need to manipulate the individual elements (say, remove one), use the masterList instead:

    removeObject = function (i)
    {
        var toRemove = this.masterList.splice(i, 1);
        if (toRemove)
        {
            this.divList.removeChild(toRemove.elt);
        }
    }
    

    See also Array.splice().

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

Sidebar

Related Questions

No related questions found

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.