jeudi 26 novembre 2015

Handlebars dont wait for Ember Ajax

My Problem is that the handlebars is not wating for the ajax request to be finished.

My console is like this:

  1. It starts with "starting" from the function in the controller.
  2. Then the {{log workouts}} in the template which is undefined because the ajax is yet not ready.
  3. And at the end the data from the request.

So this is a part of my code of my workouts controller

workouts: function() {
        console.log("starting");

        this.get('session').authorize('authorizer:custom', (headerName, headerValue) => {
            var obj = {};
            obj[headerName] = headerValue;

            Ember.$.ajax({
                type: "GET",
                url: this.requestEndpoint,
                headers: obj,
            }).success(function(data) {
                console.log("ajax: "+JSON.stringify(data));
                return data;
            }).error(function(error) {
                return error;
            });
        }); 
  }.property()

And the Handlebars Template is like this:

{{log workouts}}

How do I solve this? Maybe: Is there a way to transform this code into a promise? Or is there a "wait for ember" option?




Aucun commentaire:

Enregistrer un commentaire