kgish
1
I want to use a remote service that exposes an api for returning a random item, something like this:
http://remote-service.com/api/v1/items/random
However, from within Ember I cannot get the model to refresh and make an additional request to pick up the newer results.
I’ve tried various things, including:
model.refresh();
transitionToRoute('items.random');
but this doesn’t seem to work either.
Is there an easier more elegant manner to achieve this that I am overlooking?
Does reload not do the job?
kgish
3
Sure, if I hit F5
(refresh browser) it works fine.
Only using the button with action doesn’t
kgish
5
Yes, as I said in the original message (I meant model.reload()
sorry). Here’s a code sample:
actions: {
...
random: function() {
var model = this.get('model');
if (model) {
var _this = this;
model.reload().then(function(model){
_this.transitionToRoute('entries.random');
});
}
},
...
}
Not sure but this.controller.get('model').reload()
seems better. You need to reload the data on the controller.
kgish
7
That’s not going to work because the action is being handled from within the controller already and NOT within the route, any other ideas?
Not much ideas. Do you use setupController
on the route? I remember reading this and perhaps your model is also not fetched.
To me requesting a random item seems to fit better with store.query
as opposed to refreshing a model.