From 4eecf7bd544218597e2685d7541e72e36672b2ef Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 7 Apr 2016 17:52:13 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9cup=C3=A8re=20le=20contenu=20du=20fichie?= =?UTF-8?q?r=20JSON=20et=20l'affiche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/app/templates/sounds.hbs | 4 +++- js/app/views/sounds.js | 20 ++++++++++++++++++-- sounds.json => sounds/sounds.json | 0 3 files changed, 21 insertions(+), 3 deletions(-) rename sounds.json => sounds/sounds.json (100%) diff --git a/js/app/templates/sounds.hbs b/js/app/templates/sounds.hbs index 8b13789..d62f6e2 100644 --- a/js/app/templates/sounds.hbs +++ b/js/app/templates/sounds.hbs @@ -1 +1,3 @@ - +{{#each data.sounds}} + {{title}} +{{/each}} diff --git a/js/app/views/sounds.js b/js/app/views/sounds.js index f924a0b..f5142b0 100644 --- a/js/app/views/sounds.js +++ b/js/app/views/sounds.js @@ -2,13 +2,29 @@ define( 'views/sounds', [ 'marionette', + 'jquery', 'hbs!templates/sounds' ], - function (Marionette, SoundListTemplate) { + function (Marionette, $, SoundListTemplate) { "use strict"; var SoundListView = Marionette.LayoutView.extend({ - template: SoundListTemplate + template: SoundListTemplate, + initialize: function() { + var that = this; + + this.data = {}; + + $.get('/sounds/sounds.json', function(json) { + that.data.sounds = json; + that.render(); + }); + }, + serializeData: function () { + var viewData = {data: this.data}; + + return _.extend(viewData, Marionette.LayoutView.prototype.serializeData.apply(this, arguments)); + } }); return SoundListView; diff --git a/sounds.json b/sounds/sounds.json similarity index 100% rename from sounds.json rename to sounds/sounds.json