简体   繁体   English

从ember-engine内部导入模型

[英]Import model from inside ember-engine

I have an Ember.js application with an ember-engine added as an external addon, and both the parent application and the engine share the store. 我有一个Ember.js应用程序,其中添加了ember引擎作为外部插件,并且父应用程序和引擎都共享商店。 This creates an issue because when fetching a model in a route from the engine, the fact of having the store shared makes the parent application to crash saying that it does not know the model. 这造成了一个问题,因为从引擎获取路由中的模型时,共享存储的事实使父应用程序崩溃,说它不知道模型。

Copying the model from inside the engine into the parent's models fixes it, but it goes against the principle of isolation. 将模型从引擎内部复制到父模型中可以解决该问题,但是这违背了隔离原则。

I wonder if there is any way of importing an engine's model into the parent application, because even if that also makes the parent aware of the engine's model, at least it won't be replicating code. 我想知道是否有任何方法可以将引擎的模型导入父应用程序,因为即使这也使父引擎知道了引擎的模型,至少它不会复制代码。

Since it is an addon, I supposed this would work: 由于这是一个插件,所以我认为这可以工作:

`import DockerComposeModel from 'ember-stack-builder-engine/models/docker-compose'`

But throws an error 但是抛出一个错误

Error: Could not find module `ember-stack-builder-engine/models/docker-compose` imported from `bde-integrator-user-interface/application/controller`

Can you please show us some code How you are configuring the engine. 您能告诉我们一些代码如何配置引擎。

normally engine and app shares the model and you do not have to use import. 通常,引擎和应用共享模型,而您不必使用导入。

You can directly use this.findRecord(ModelName) but if it does not work then please share your code. 您可以直接使用this.findRecord(ModelName)但如果它不起作用,请共享您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM