0

I have json file that I use like a simple database kind of system.

jsondata = {

"project1":
{"titel":"letterfabriek", "omschrijving":"Doe", "linktext":"http://www.website.nl", "img":"ding.png"},
"project2":
{"titel":"John", "omschrijving":"Doe", "linktext":"http://www.website.nl", "img":"ding.png"}

}

When someone click on a button I want that project to be selected out of the json file.

So for instance

<li class="portfolio" data-titel="project1"><img src="img/portfolio/1.png"></li>

On the hit I get the project titel like :

project = $(this).attr("data-titel");

Now as last I want this title displayed in a div with the class titel

I know this will work:

$(".titel").text(jsondata.project1.titel);
$(".description").text(jsondata.project1.omschrijving);

But instead I want the project title be the var project. So something like

jsondata. + var project + .titel etc..

How can I do this?

Thanks in advance

Merijn de Klerk
  • 953
  • 2
  • 11
  • 21
  • 1
    You should be able to do: `jsondata[project].titel` this will get the project named under `var project` ie - `project1` – Adjit Dec 28 '15 at 17:08

1 Answers1

1
var project = $(this).attr("data-titel");
$(".titel").text(jsondata[project].titel);
$(".description").text(jsondata[project].omschrijving);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928