I'm working with ExpressionEngine and have converted my channel entries into JSON, that works nicely.
What I am trying to do is populate a Sweet Alert 2 overlay with information from specific JSON objects using an ID stored in a data-*
attribute.
Here is an example of the JSON:
var director_45 = {
"title": "Andy H",
"entry_id": 45,
}
And if I do a simple jQuery alert like this, it returns my name:
alert(director_45.title)
However, if I do something like this in jQuery:
$('.trigger-director').on('click', function() {
var director_id = $(this).data('director');
var director = 'director_' + director_id;
alert(director.title);
});
With this HTML to fire it:
<div class="col-xs-6 col-md-3">
<div class="director-box">
<img src="/images/made/images/uploads/images/Andy_400_300_c1.jpg" class="img-responsive" width="400" height="300" alt="" />
<h3>Andy H</h3>
<p>Director</p>
<a class="trigger-director" data-director="45">Find out more</a>
</div>
</div>
The alert upon clicking the 'Find out more' link only shows "Undefined".
I've created a jsFiddle link here too - https://jsfiddle.net/zu103vxc/
Any idea what it is that I'm doing wrong and/or missing?