Reputation: 3749
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;
}
});
Upvotes: 0
Views: 173
Reputation: 1076
If you use model = Ember.Object.create({title: 'old Title'})
, then you can use model.set('title', 'new Title')
to set a new title, that will be updated on the view automatically.
Here is a simple example JSBin: http://emberjs.jsbin.com/xuzevizabe/2/edit
But it seems that you instead want to use ember-data to handle your models.
Upvotes: 1