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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:06:31+00:00 2026-06-04T09:06:31+00:00

I am using d3.js library to generate contents based on data. Here is a

  • 0

I am using d3.js library to generate contents based on data.

Here is a simplified example.

data_arr = [0,1,2,3,4];
d3.select("#mylist").selectAll('li').data(data_arr).enter().append("li").html(
    function(d)
    {
        var element = document.createElement('div');
        element.innerHTML = '<div id="innerDiv">' + d + '</div>';
        return element.innerHTML;
   });

If I change my array, for example the new data is [5,3]. How is the best way to rebind and show the new html? Do I have to call the same sentence again or is it a better way?

Consider the case of a more complex data structure.
i.e.

data_arr = [obj1, obj2, obj3, obj4]; 

and

element.innerHTML = '<div id="innerDiv">' + d.field + '</div>';

What happens if I do obj1.field = ‘newValue’. How is the rebind done?

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-06-04T09:06:32+00:00Added an answer on June 4, 2026 at 9:06 am

    Use a function. For example, here’s a function that will populate a list from an array of strings:

    function list(ul, data) {
      var li = ul.selectAll("li").data(data);
      li.exit().remove();
      li.enter().append("li");
      li.text(function(d) { return d; });
    }
    

    Now if you want to initialize your list, you can say:

    d3.select("#list").call(list, [0, 1, 2, 3, 4]);
    

    Then later if you want to update, you can say:

    d3.select("#list").call(list, [5, 3]);
    

    If you prefer (and you don’t need method chaining), you can write this without selection.call:

    list(d3.select("#list"), [5, 3]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using PHPPdf library to generate PDFs on the fly in my Symfony2 app.
I am using the pdflib library to generate the pdf for my online booking
I am using Flex's Alchemy library to generate SWC's out of C files. I
I'm using the flying-saucer library to generate a PDF in a servlet that then
I am writing a library to generate PDF reports using prawn reports. One of
I am using comtypes to generate wrappers for a certain com library. I am
I'm using Subsonic 2.2 Subcommander(Sonic.exe) to generate my DAL in a standalone class library
I'm using the mPDF library to generate PDF docs directly from HTML output. The
I'm creating a newspaper authoring system. Today I'm using Aspose.Words library to generate newspaper
I'm using the HighStock stock charting library to generate a basic OHLC stock chart.

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.