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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:32:15+00:00 2026-06-18T07:32:15+00:00

I am using the reveal module pattern for my javascript and I am having

  • 0

I am using the reveal module pattern for my javascript and I am having the darndest time getting the css binding to work correctly with knockout.

My JS

    my.js.module = (function ($) {
        "use strict";

        var my = { 
            testUrl: null 

        },
            testModel= {
                stuff: [{
                    "testOne": null
                }]
            },
            testViewModel = null,
            testId: null;

    my.bindStuff = function () {

        testViewModel =  ko.mapping.fromJS(testModel);

        ko.applyBindings(testViewModel, $(my.testId).get(0));

        $.getJSON(my.testUrl,
            {},
            function (data) {

                var testModelData = {
                    stuff: data
                };

                ko.mapping.fromJS(testModelData, testViewModel);
            });
    };

    return my;
}(jQuery));

and in my cshtml I have

<tbody data-bind="foreach: stuff">
                <tr>
                    <td data-bind="text: testOne"></td> 
                </tr>
            </tbody>

Now I want to use the css binding via knock out to get a css value based on the value of what testOne is, it can be one of three things. I know it will be a ko,computed function but i cant quite figure out how to get each particular instance of stuff to look at testOne and get the correct value to determine what to return via the ko.computed function.

if someone could help me out i would be greatly appreciative.

  • 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-18T07:32:17+00:00Added an answer on June 18, 2026 at 7:32 am

    This fiddle shows how to use mapping with an array and set the class of an element via knockout, its not an exact match to your code but should help:
    http://jsfiddle.net/davidoleary/UHaVV/

    var newData = {    
        test:"this is a test",
        stuff:[
            {"testOne":"Event1"},
            {"testOne":"Event2"},
            {"testOne":"Event3"}
        ]
    };
    
    var viewModel = ko.mapping.fromJS( newData );
    ko.applyBindings(viewModel);
    
    <div data-bind="text:test"></div>
        <ul data-bind="foreach: stuff">
        <li><span data-bind="text: testOne, attr:{class: testOne}"></span></li>
    </ul>
    

    Also have a look at this question to see two ways of setting the class:

    Knockout binding css class to an observed model property

    You can use attr or the new css binding both are refereed to in the question above.

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

Sidebar

Related Questions

I am using the following module to reveal a sub menu: icisSite.fatNav = function(trigger){
I'm using css to hide content that I want to reveal when a person
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using CI for the first time and i'm smashing my head with this seemingly
Using import datetime in python, is it possible to take a formatted time/date string
I'm trying to get the jquery draggable function to work, particularly the stacking feature,
I'm using Foundation Reveal modals to display first a Reveal containing a calendar with
I'm using show/hide to reveal groups of items based on their class attributes. How
I am using Jquery Validation Engine http://posabsolute.github.com/jQuery-Validation-Engine/ and I just want to reveal a
I'm using cakephp to build a survey and want to use javascript (specifically jquery

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.