With the recent update, I know that in routers and controllers, I can easily just do this.store.find('model')
. However I have some functions that need to call find
that are not in routers and controllers. So how can I get an instance store
from anywhere in an Ember App?
I know worst comes to worst I can do App.__container__.lookup('store:main')
, but I'll try to stay away from that.
Ember Data is a model library that manages finding data, making changes, and saving it back to the server. It's a bit like an ORM in that it abstracts the underlying persistence mechanism behind an easy to use API. If you're familiar with using ORMs, you will find Ember Data easy to work with.
The store contains all of the data for records loaded from the server. It is also responsible for creating instances of Model that wrap the individual data for a record, so that they can be bound to in your Handlebars templates. Define your application's store like this: app/services/store.js.
The TRANSITION doc says that you can do this to inject the store into components :
App.inject('component', 'store', 'store:main');
You might be able to change 'component'
to 'view'
or to 'model'
, but I'm not sure about that.
You can do
App.Model.store.find('model')
If you have a particular attribute to filter with, you can do:
App.Model.store.find('model', {'attribute_name' : 'matching_to_this_value'})
See more on this post.
You can try to do
this.get('controller').get('store').find('model')
That would wok in a View for example.
With Ember Data 1.0.0-beta.X
:
App.YourModelType.store.find("yourModelType", someId).then(
function(modelInstance) {
...
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With