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 theforeach) 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>