本文介绍了如何获取Ember Data的“store”从应用程序的任何地方,我可以做store.find()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着最近的,我知道在路由器和控制器中,我可以轻松地执行 this.store.find('model')。但是我有一些功能需要调用不在路由器和控制器中的 find 。那么,如何从Ember App中的任何地方获取一个实例 store

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?

我知道最糟糕的是最糟糕的我可以做 App .__ container __。lookup('store:main')但是我会尽量远离这个。

I know worst comes to worst I can do App.__container__.lookup('store:main'), but I'll try to stay away from that.

推荐答案

doc说你可以这样做来将商店注入到组件中:

The TRANSITION doc says that you can do this to inject the store into components :

App.inject('component', 'store', 'store:main');

您可能可以更改'组件''view''model',但我不确定。

You might be able to change 'component' to 'view' or to 'model', but I'm not sure about that.

这篇关于如何获取Ember Data的“store”从应用程序的任何地方,我可以做store.find()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:36