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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:15:52+00:00 2026-06-17T17:15:52+00:00

I have issue to dynamically create list(ol or ul). The problem I face is

  • 0

I have issue to dynamically create list(ol or ul). The problem I face is that sometimes I need ordered list and sometimes un-ordered depending upon the JSON. I am using knockout, Here is my html,

<ol data-bind="foreach: items" ><li><a data-bind="text: $data"></a></li></ol>

Here is my JSON,

{
   items: ['a','b','c'],
   orderedList: true
}

You can see that orderedList may be true or false. If true then I need to use ol and if false I need to use ul. I also to avoid replication. Any way to do this.

  • 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-17T17:15:53+00:00Added an answer on June 17, 2026 at 5:15 pm

    Here is a crude sample I put together, was not able to test it. But you can get the idea.

    <!-- ko if : orderedList -->
    <ol>
    <!-- /ko -->
    <!-- ko ifnot : orderedList -->
    <ul>
    <!-- /ko -->
    <!-- ko foreach: items -->
    <li><a data-bind="text: $data"></a></li>
    <!-- /ko -->
    <!-- ko if : orderedList -->
    </ol>
    <!-- /ko -->
    <!-- ko ifnot : orderedList -->
    </ul>
    <!-- /ko -->
    

    EDIT: There is no if-else condition in knockout. So you will have to rely on using multiple Ko if statements.

    EDIT2: The version of the code that worked for the OP.

    <!-- ko if : orderedList -->
    <ol data-bind="foreach: items">
        <li><a data-bind="text: $data"></a></li>
    </ol>
    <!-- /ko -->
    <!-- ko ifnot : orderedList -->
    <ul data-bind="foreach: items">
        <li><a data-bind="text: $data"></a></li>
    </ul>
    <!-- /ko -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I need to create a view or a table valued function that returns one
I have a button that will create a new entry (row in a table)
I have a dynamically generated list of students. I want the users to capture
I need to create a number of UIScrollViews dynamically and fill them with content.
So I have one activity with a listview in it that is dynamically updated
I'm trying to create a timer in Javascript and I have a specific issue
I'm creating an iPhone app and I need the ability to dynamically create a
I have issue where i want to create Dynamic function which will do some
i have a bunch of code where i dynamically create dropdown boxes in javascript.

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.