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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:24:43+00:00 2026-06-07T06:24:43+00:00

I want to create a 3×3 grid with images loaded using knockout binding <fieldset

  • 0

I want to create a 3×3 grid with images loaded using knockout binding

<fieldset class="ui-grid-b" data-bind="foreach: Icons">
 <div>
    <img alt="" src="../res/placeholder.png" style="width: 80px; height: 80px" />
 </div>
</fieldset>

The Images property is from the view model and it is loaded asynchronously by a ajax call.

I need to set the div for each image like this:

for 1st div: <div class="ui-block-a" />
for 2nd div:<div class="ui-block-b" />
for 3rd div:<div class="ui-block-c" />
for 4th div:<div class="ui-block-a" />
for 5th div:<div class="ui-block-b" />
for 6th div:<div class="ui-block-c" />
…

so the class name is “ui-block-” + div_index % 3

the problem is I do not know how to set the class name.
i tried using a computed observable but i cannot get the actual object(the icon model) in order to be able to return an Icons.IndexOf(icon) % 3

  • 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-07T06:24:45+00:00Added an answer on June 7, 2026 at 6:24 am

    Using Knockout 2.1 inside a foreach you have access to the $index variable.

    <div data-bind="attr: {'class': $root.indexLetter($index())}">
    

    Create a method in your ViewModel like this:

    viewModel.indexLetter = function(index) {
        var abc = 'abc';
        return 'ui-block-' + abc.charAt(index % 3);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want create a custom json data from the mssql 2008 results so that
i want create image animation , i have 50 images with png format now
I want to create a Silverlight app to extract and manipulate data from an
I want create some view, and add dynamically to it text and images Somebody
I want create a pdf using iText. The method which does this is a
I have some class with properties firstName and lastName. I want bind TextBlock to
I want create a ModelForm class where model is a parameter passed from the
I want create texture atlas(matrix of images) from multiple images.Is their any applescript that
Basically i want to create XMLDesigner kind of thing in Flex, using which user
I have data in a hashmap, and I want to create a histogram over

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.