Open HYannick opened 9 years ago
cfr email. Corriger la structure d'abord:
https://github.com/m2dimi/ciwo/blob/gh-pages/js/script.js, ligne 74
$.getJSON("json/ciwoData.json", function(data) {
console.log(data);
var years_box = $('#years');
$.each(data, function(i, result){
years_box.append('<div class="year"></div>');
})
});
Ok j'ai changé la structure, mais j'arrive pas à afficher les années voici ce que j'ai fait en m'aidant de votre code. ça me met un undefined sur une seule année.
$.getJSON("json/ciwoData.json", function(data) { console.log(data); var years_box = $('#years');
$.each(data, function(i, result){
var yearData = data[i].year;
years_box.append('<div class="year">'+ yearData +'</div>');
})
});
j'ai réussi =)
Le soucis est qu'il affiche toutes les années. Faut-il changer du coup les data json ? par exemple centraliser tous les films de 1945 de cette manière ?
"1945" : [ { "title":"La Cage aux rossignols", "genre":"Drame", "langue":"Français", "jpbox":"http://www.jpbox-office.com/cinema/images/posters/cagerossignols.jpg", "year":"1945", "watchers":"5 084 805", "presenceFemme":"non", "b":"", "c":"", "url":"http://www.imdb.com/title/tt0039234/?ref_=fn_al_tt_1", "director":"Jean Dréville", "affiche":"http://fr.web.img2.acsta.net/r_640_600/b_1_d6d6d6/medias/nmedia/18/35/29/68/18380162.jpg", "rating":"6,7", "stars":"Noël-Noël|Micheline Francey|Georges Biscot", "syn":"Add a Plot" }, { "title":"Le Cavalier noir", "genre":"Action-aventure", "langue":"Français", "jpbox":"http://www.jpbox-office.com/cinema/images/posters/12492-20111124081112.jpg", "year":"1945", "watchers":"3 672 572", "presenceFemme":"non", "b":"", "c":"", "url":"http://www.imdb.com/title/tt0214567/?ref_=fn_al_tt_2", "director":"Gilles Grangier", "affiche":"", "rating":"4,3", "stars":"Georges Guétary|Mila Parély|Jean Tissier", "syn":"In Flanders in the eighteenth century, Ramon de Ortila, a young lord who has been dispossessed of property has turned into a gentleman brigand. His main target is Monsieur de Saint-Brissac,... See full summary »" }, { "title":"Le Livre de la jungle (1945)", "genre":"Action-aventure", "langue":"Américain", "jpbox":"http://www.jpbox-office.com/cinema/images/posters/12592-20120107040118.jpg", "year":"1945", "watchers":"5 084 962", "presenceFemme":"non", "b":"", "c":"", "url":"http://www.imdb.com/title/tt0034928/?ref_=fn_al_tt_3", "director":"Zoltan Korda", "affiche":"", "rating":"6,8", "stars":"Sabu|Joseph Calleia|John Qualen", "syn":"A boy raised by wolves tries to adapt to human village life." }, { "title":"Pêché mortel", "genre":"Thriller", "langue":"Américain", "jpbox":"http://www.jpbox-office.com/cinema/images/posters/nophoto.jpg", "year":"1945", "watchers":"1 798 915", "presenceFemme":"non", "b":"non", "c":"", "url":"http://www.imdb.com/title/tt0037865/?ref_=fn_tt_tt_9", "director":"John M. Stahl", "affiche":"http://fr.web.img3.acsta.net/r_640_600/b_1_d6d6d6/medias/nmedia/18/35/62/76/18414457.jpg", "rating":"7,7", "stars":"Gene Tierney|Cornel Wilde|Jeanne Crain", "syn":"A writer meets a young socialite on board a train. The two fall in love and are married soon after, but her obsessive love for him threatens to be the undoing of both them and everyone else around them." } ],
Exactement, il faut aussi regrouper par année. Voici ma methode (sans changer de json):
var data_groups = {},
years = [];
for(var i=0; i<data.length; i++) {
if(!data_groups[data[i].year]) {
data_groups[data[i].year] = {
d: [],
y: data[i].year,
count: 0
};
}
data_groups[data[i].year].count++;
data_groups[data[i].year].d.push(data[i]);
}
// rebuilding the year list
for(var i in data_groups) {
years.push(data_groups[i])
}
console.log('unsorted', years);
// sort years
years.sort(function(a,b) {
return a.y > b.y?-1:1
});
console.log('sorted', years)
Problème pour créer la boucle afin d'actualiser les différents sliders. Voici les lignes de code ou j'exploite le json
Owl est le plugin de carousel que j'ai utilisé. J'y ai intégré les données json.
var owl = $(".sliding"); owl.owlCarousel({ jsonPath : 'json/ciwoData.json', //On récupère les données JSON jsonSuccess : customDataSuccess, items : 3 });
Mais cela ne fonctionne que pour une année ( 1950 ) Comment le faire fonctionner pour toutes les années ?