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

The Archive Base Latest Questions

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

I need to build a list with 6 li ‘s and their values (empty

  • 0

I need to build a list with 6 li‘s and their values (empty or not) and then append it to an existing li.

Having these results in return from an sql query:

id_news  title      category  order
-------  --------   --------  -----
3        Alex...    12        1
12415    Obama...   3         3

With that data I need to build an in order by order list, and by that I mean that the list should be something like:

<ul>
    <li data-order="1"> Alex... </li>
    <li data-order="2"> No featured news here, click to add </li>
    <li data-order="3"> Obama... </li>
    <li data-order="4"> No featured news here, click to add </li>
    <li data-order="5"> No featured news here, click to add </li>
    <li data-order="6"> No featured news here, click to add </li>
</ul>

So, my questions are:

  • Should I have a predefined list and add data there?
  • Or, should I do it while building the list? If so, how?

The jQuery code that I have by now:

var sublist = '<ul id="order_list"> <h3> Order list: </h3>';
$.each(data, function(index, value) {
  sublist += '<li data-target="'+value['id_news']+'">'+value['headline']+'</li>';
});
sublist += '</ul>';
list.append(sublist);
  • 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-04T08:04:32+00:00Added an answer on June 4, 2026 at 8:04 am

    The important thing is to remember to just get all the markup string text the way you want it before inserting into the DOM, that’s going to be 99% of the optimization (not that you aren’t, just pointing out that that’s definitely the focus to keep).

    As for accomplishing that: use the same code you have for creating the markup, but sort your “data” array first. Use javascript arrays’ “sort” function for that. This jsfiddle shows it happening.

    var data = [{order:5}, {order:45}, {order:4}, {order:200}];
    data.sort(function(a,b){return a.order-b.order;});
    
    $.each(data,function(index, value){
        document.write(value.order+'<br/>');
    });
    
    // output shows the array ordered by the val of the objects' order prop
    

    I’m assuming that your data array holds objects with an order property that is numeric. Of course, if the property is named something else then change accordingly, and if it’s a string instead of numeric, then use Number() within the function in order for the math to work.

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

Sidebar

Related Questions

I need to use group_concat to build a list of comma separated values but
I need to build a list of all the file extensions of binary files
I need to build up a List<object> and cache the list and be able
I need to dynamically build a list of textboxes using javascript and jquery. The
I need to build a sorter class for a List. I would like the
I am trying to build a list of strings that I need to pass
I need to build some searching logic that produces ranked results. A simple example
When I build a list using foldLeft I often get annoyed at having to
I need to build a list of strings with a checkbox next to each
I need to build a list of all roles on an ASP.NET web site,

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.