From 502e60e94082d296fe2af32f989f2242a4daa3c0 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Mon, 20 Oct 2014 12:22:41 +0700 Subject: [PATCH] update to parse JSONObject response instead --- js/app.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/js/app.js b/js/app.js index c7f7df3..3f479e6 100755 --- a/js/app.js +++ b/js/app.js @@ -21,20 +21,9 @@ var groups = [ {id: "1", name: "sf"}, {id: "2", name: "major"} ]; -var theaters = [ - {id: "1", name: 'Sf Emporium', code: "9909"}, - {id: "2", name: 'Sf NgamWongWan', code: "9934"} -]; - -var showtimes = [ - {id: "1", name: "The Cove (1999)", showtimes: ['10:30', '13:30']}, - {id: "2", name: "The Notebook (2004)", showtimes: ['15:30', '17:30']}, -]; - var restUrl = 'http://showtimes.everyday.in.th/api'; var today = new Date(); - App.Router.map(function() { this.resource('about'); this.resource('api'); @@ -53,11 +42,14 @@ App.GroupsRoute = Ember.Route.extend({ App.TheatersRoute = Ember.Route.extend({ model: function(params) { - return $.getJSON(restUrl+'/theaters/'+params.name+'/'); + return $.getJSON(restUrl+'/theaters/'+params.name+'/').then(function(data) { + return data.objects.map(function(theater) { + return theater; + }); + }); } }); - App.ShowtimesRoute = Ember.Route.extend({ model: function(params) { var theatersObjs = this.modelFor('theaters'); @@ -65,7 +57,11 @@ App.ShowtimesRoute = Ember.Route.extend({ restUrl, '/showtimes/', theatersObjs[0].group, '/', params.code, '/?d=', moment(today).format('YYYY-MM-DD') ]; - return $.getJSON(url.join('')); + return $.getJSON(url.join('')).then(function(data) { + return data.objects.map(function(showtimesItem) { + return showtimesItem; + }); + }); } });