Rebooting a model using Ember Data

I am trying to poll additional data using the documented function model.reload ()

App.ModelViewRoute = Ember.Route.extend({ actions: { reload: function() { this.get('model').reload(); } } }); 

But I get an error message saying ...

 undefined is not a function TypeError: undefined is not a function 

Is there a better way to do this, it seems like I cannot access the model this way from the route?

Here is the router

 App.Router.map(function() { this.route('video', { path: '/videos/:video_id' }); }); 

Here is the route

 App.VideoRoute = Ember.Route.extend({ model: function(params) { return this.store.find('video', params.video_id); }, actions: { reloadModel: function() { // PROBLEM HERE // this.get('model').reload(); Ember.Logger.log('reload called!'); } } }); 

Here is a model

 App.Video = DS.Model.extend({ title: DS.attr('string'), status: DS.attr('string') }); 

And patterns

 <script type="text/x-handlebars" data-template-name="application"> <h1>Testing model reloading</h1> {{#link-to "video" 1}}view problem{{/link-to}} {{outlet}} </script> <script type="text/x-handlebars" data-template-name="video"> <h1>Video</h1> <h2>{{title}}</h2> {{model.status}} <p><button {{action 'reloadModel'}}>Reload model</button></p> </script> 

I made jsbin problems here:

http://jsbin.com/wofaj/13/edit?html,js,output

I really can't understand why rebooting gives me this error. Any advice would be highly appreciated.

thanks

+6
source share
3 answers

Since model already exists as a hook on Ember.Route, you cannot get this as a property.

Instead, you can do the following:

 this.modelFor('video').reload(); 

Technically, you could do this.get('currentModel').reload(); too, but it's undocumented and probably won't be available in the future.

+10
source

The route refresh method will do what you after

 App.VideoRoute = Ember.Route.extend({ model: function(params) { return this.store.find('video', params.video_id); }, actions: { reloadModel: function() { this.refresh() } } }); 

API docs

+13
source

The routing model feature provides a capture for loading your controller data. There is a special section in the ember guide .

1) If you want to access your content, it will look like this:

 reload: function() { this.controller.get('content'); } 

2) reloading is a method available for ember-data objects. In your example, you are loading a js object ({id: 2, title: "Test video title 2", status: "downloading"}).

0
source

All Articles