How to get Ember Data's “store” from anywhere in the application so that I can do store.find()?

后端 未结 4 1895
我寻月下人不归
我寻月下人不归 2021-02-07 09:47

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

相关标签:
4条回答
  • 2021-02-07 10:17

    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.

    0 讨论(0)
  • 2021-02-07 10:17

    With Ember Data 1.0.0-beta.X:

    App.YourModelType.store.find("yourModelType", someId).then( 
      function(modelInstance) { 
      ...
      });
    
    0 讨论(0)
  • 2021-02-07 10:23

    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.

    0 讨论(0)
  • 2021-02-07 10:30

    You can try to do

    this.get('controller').get('store').find('model')
    

    That would wok in a View for example.

    0 讨论(0)
提交回复
热议问题