jeudi 4 juin 2015

Ember Routing Model Observing Updates in Handlebars Template

How do I update a model property once a promise (via Ajax call) has returned? Here is my go at it that is not working. In the docs, it appears observing takes place using Ember.set but the model I am returning is not an Ember model object so I don't think that works.

import Ember from 'ember';

export default Ember.Route.extend({

    model: function() {

        var model = { title: "Lorem Ipsum" };
        var userSubscriptions = [];
        var App = this;

        Ember.$.getJSON('http://localhost:1337/company/usersubscription/active/', parameters, function(userSubscriptions) {

            userSubscriptions.forEach(function(data) {

                var userSubscription = App.store.push('usersubscription', data);
                userSubscriptions.pushObject(userSubscription);

                model.title   = "No Lorem Ipsum";
                model.objects = userSubscriptions;

            });

        });

        return model;

    }

});




Aucun commentaire:

Enregistrer un commentaire