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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:52:17+00:00 2026-06-07T15:52:17+00:00

I am using knockout.js and the ko.mapping plugin to bind a list of json

  • 0

I am using knockout.js and the ko.mapping plugin to bind a list of json object to an html grid. Lets call each item a card (simplified example below)

{
    "card": [
        {
            "Id": "cards/1",
            "category": "Demo",
            "title": "Card 1",
            "description": "bla bla",
            "picture": "demo1.jpg ",
            "madeBy": "user/1"
        },
        {
            "Id": "cards/2",
            "category": "Demo",
            "title": "Card 2",
            "description": "bla bla",
            "picture": "demo2.jpg",
            "madeBy": "user/2"
        }
    ]
}

I bind each elemet like this:

 <div data-bind="foreach: card">
    <span data-bind="text:title"></span>
    <a data-bind='click: show'><img data-bind="attr:{src: picture}" /></a>
</div>

When the user clicks on a card, I would like to show the selected card in a different div (outside of the foreach) with some more properties from the selected json object

Who do I bind to one selected card from the view model?

I am trying something like (but not getting any data):

<h1 data-bind="text: $data.title"> </h1>
  • 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-07T15:52:18+00:00Added an answer on June 7, 2026 at 3:52 pm

    You will want to do this by tracking the selected card on the ViewModel that holds the cards. Here is a fiddle demonstrating this simply. Here is the modified HTML and JS (this has been simplified for the purpose of a demo, and I’m not using mapping, but you get the idea):

    HTML:

    <div data-bind="foreach: cards">
        <span data-bind="text:title"></span>
        <a data-bind='click: $parent.selectedCard'>ImagePlaceholder</a>
        </br>
    </div>
    
    <div data-bind="with: selectedCard">
        <h1 data-bind="text: title"></h1>
        <span data-bind="text: description"></span>
    </div>
    

    JS

    var ViewModel = function(cards) {
        this.cards = ko.observableArray(
            ko.utils.arrayMap(cards, function(c) {return new Card(c);})
        );
        this.selectedCard = ko.observable();
    };
    

    Note that the click setting the selected card directly, without needing to use wrapper “show” function. Since observables are functions, we can skip that step (unless of course you need to do more in the show function).

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

Sidebar

Related Questions

I'm using a combination of Knockout.js + the Knockout mapping plugin + jQuery in
Using knockout's mapping plugin, how would I go about displaying the information from and
We are using knockout and the knockout mapping plugin to facilitate databinding in our
I am using Knockout and the Knockout Mapping plugin. My MVC3 Action returns a
Using knockout.js, is it possible to bind to a property of a child object
I am binding a list of objects to a select using knockout. Object Class
I'm retuning a JSON object from a web service and using knockout 2.01 to
Using Knockout with the Underscore.js template engine... When I try to bind 2004 list
This is my example below. I'am using knockout.mapping plugin in my project. I want
I'm using knockout.js and twitter bootstrap's modal plugin to data-bind the user's email address

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.