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

  • SEARCH
  • Home
  • 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 6195791
In Process

The Archive Base Latest Questions

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

Initially I have this layout: <ul id=state_${abbr}></ul> on the jsp page and I need

  • 0

Initially I have this layout:

<ul id="state_${abbr}"></ul>

on the jsp page and I need to load this JSON map of map to the layout.

coverage.phone.data = {
"CA" : {
    "LOS ANGELES" : "1111", 
    "TORRANCE" : "2222", 
    "SANTA MONICA" : "3333"
}, 
"UT" : {
    "APPLE VALLEY" : "4444",
    "SALT LAKE CITY" : "5555"
}, 
"NV" : {
    "BOULDER CITY" : "6666", 
    "LAS VEGAS" : "7777",
    "CARSON CITY" : "8888"
}

}

The finally result would be like this:

<ul id="state_CA">
    <li><p>City: <a id="1111" href="#">LOS ANGELES</a></p></li>
    <li><p>City: <a id="2222" href="#">TORRANCE</a></p></li>
    <li><p>City: <a id="3333" href="#">SANTA MONICA</a></p></li>
</ul>
<ul id="state_UT">
    <li><p>City: <a id="4444" href="#">APPLE VALLEY</a></p></li>
    <li><p>City: <a id="5555" href="#">SALT LAKE CITY</a></p></li>
</ul>
<ul id="state_NV">
    <li><p>City: <a id="6666" href="#">BOULDER CITY</a></p></li>
    <li><p>City: <a id="7777" href="#">LAS VEGAS</a></p></li>
    <li><p>City: <a id="8888" href="#">CARSON CITY</a></p></li>
</ul>

It will list the city name and location id for each state area. There is an onclick event for each link in the “li” tag. The click function will trigger some backend call that sends the location id, which will be the id of the a tag, in the request.

Looking up iterate maps, I found the jQuery.each() Hence, I wrote the following javascript to fill the unorder lists, “ul”.

// create the li and click function    
var createLink = function(map) {
        var link = ""; 
        $.each(map, function(key, value){
            link += "<li><p>City: <a id=\"" + value + "\" href=\"#\">" + key + "</a></p></li>";
            $("#"+value).click(function(){
                callBackend(this); 
            }); 
        }); 
        return link; 
    };
    // append the li(s) to the ul tags
    $.each(coverage.phone.data, function(i, val){
        var result = createLink(val);
        $("#state_"+i).append(result);  
    });

Essentially, I need to iterate the JSON map object to fill the list. I don’t particularly like to nested the each functions with any click events.

Unfortunately, nothing is being appended and I couldn’t figure out why. Any help would be greatly appreciated.

  • 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-24T03:31:48+00:00Added an answer on May 24, 2026 at 3:31 am

    Take a look at this

    http://jsfiddle.net/HsZp6/4/

    $(function(){ 
        / create the li and click function    
        var createLink = function(map) {
            var link = ""; 
            $.each(map, function(key, value){
                link += "<li><p>City: <a id=\"" + value + "\" href=\"#\">" + key + "</a></p></li>";
                $("#"+value).click(function(){
                    callBackend(this); 
                }); 
            }); 
            return link; 
        };
        // append the li(s) to the ul tags
        $.each(coverage.phone.data, function(i, val){
            var result = createLink(val);
            $("#state_"+i).append(result);  
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iframe on a page that I need to initially have a
I have an activity with the following layout. So in this screen, initally the
I have this jQuery datepicker code that initially set the minDate of the datepicker.
I have this piece of code, <div id=event style=display:none;> <!-- initially hidden --> <div
I have a Customer class which has a representative field....this field is initially blank
I have a page with a list of items initially loaded from a include_once('show_calendarV2.php');
I have a page where I am loading bunch of images initially when the
We have a new filestream database that will be initially loaded with 65GB data,
I have an HorizontalScrollView which contains a RelativeLayout . This layout is empty in
You can see in this page: http://www.indiacustomercare.com/blogs/admin there is layout issue for some time

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.