I have this JSON file (truncated):
{
"** Please contact a mod by posting on the forums **": {
"tvdb_id": "257937",
"last_updated": 1341780286,
"images": {
"poster": "http://zapp.trakt.us/images/posters/17288.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/17288.jpg"
}
},
"Jamies Best Ever Christmas": {
"tvdb_id": "214161",
"last_updated": 1329701153,
"images": {
"poster": "http://zapp.trakt.us/images/posters/9126.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/9126.jpg"
}
},
"Kuromajo-san ga Tooru!!": {
"tvdb_id": "257914",
"last_updated": 1395775431,
"images": {
"poster": "http://zapp.trakt.us/images/posters/15640.jpg",
"fanart": "http://zapp.trakt.us/images/fanart/15640.jpg"
}
}
}
and this code:
$(".tvshow").select2({
placeholder: "Type in a TV show",
multiple: true,
maximumSelectionSize: 1,
minimumInputLength: 2,
maximumInputLength: 20,
query: function(query) {
var data = {results: []};
var value = $(".select2-input").val();
$.ajax ({
type: "GET",
url: 'shows.json',
dataType: "jsonp",
json: "callbackname",
crossDomain : true,
success: function (result) {
$.each(result, function (i, show) {
// write everything in an array
data.results.push({id: this.tvdb_id, text: this.title, poster: this.images.poster, bg: this.fanart });
console.log(this.title);
selectedTVshow = this.title;
// results = data.results;
// return array
query.callback(data);
})
},
error: function (data) {
// console.log('error');
}
})
}
})
When I search for Jamies Best Ever Christmas
I want it to return the name and the respective tvdb_id
and details.
In my above code you can see console.log(this.title);
. This is wrong, because there is no title:
value inside the JSON object. How can I get this to work and retrieve data?
Demo: http://jsfiddle.net/6pGFC/ (use first input field to get autocomplete, not second)
Thanks a lot!