简体   繁体   English

如何在余烬引擎中使用适配器

[英]How to use adapter in an ember-engines

as the title says, I have some problems understanding how to use an adapter in an ember-engines. 如标题所述,我在理解如何在余烬引擎中使用适配器方面遇到一些问题。
I am currently running my application with ember@2.15 , ember-data@2.15 and ember-engines@0.5.14 . 我目前正在使用ember@2.15ember-data@2.15ember-engines@0.5.14运行我的应用程序。 I already used an adapter in my main application, but if I tried to reproduce a basic adapter in my application, the page is loading indefinitely. 我已经在主应用程序中使用了适配器,但是如果我尝试在应用程序中重现基本适配器,则该页面将无限期加载。
In my route, I call my adapter with the findAll method: 在我的路线中,我使用findAll方法调用适配器:

  model()
    {
        "use strict";
         console.log('In my route');
         return this.get('store').findAll('my-adapter-name', {reload: true});
    }

And in my adapter, I respect the syntax that I used in my in-app adapter: 在我的适配器中,我尊重我在应用内适配器中使用的语法:

import DS from 'ember-data';
import Ember from 'ember';

export default DS.Adapter.extend({

    findAll: function (store, type, sinceToken, snapshotRecordArray)
    {
        console.log("In my adapter");
        return new Ember.RSVP.Promise(function (resolve, reject)
        {
        // I accede to my websocket service here, nothing to do with my question
        });
    },
    /* *
    * My other function, like findRecord, ect...
    */
});

As you can see, I put some console.log in my code, and I can access the message in my route, which is in my engine, but I can't access the message in my adapter, which is also in my engine. 如您所见,我在代码中放入了console.log ,可以在路由中访问消息,该路由位于引擎中,但无法访问适配器中的消息,适配器也位于引擎中。
I tried to put a console.log in an adapter in my application, and the message is properly shown, so I am sure this is because I can't access to the adapter in my engine, so if anybody has an idea to how we should configure our adapter in our ember-engines , this would be very appreciated. 我尝试将console.log放入应用程序的适配器中,并且该消息已正确显示,所以我确定这是因为我无法访问引擎中的适配器,因此如果有人对我们的想法有所了解应该在我们的ember-engines配置我们的适配器,这将非常感激。
For your information, this is an in-repo engines. 供您参考,这是一个in-repo引擎。

Just found it, this is a bit tricky, but your models (and adapters ) should be in the myApp/lib/myEngine/app/models/ , and not in myApp/lib/myEngine/addon/models . 刚刚发现,这有点棘手,但是您的models (和adapters )应该在myApp/lib/myEngine/app/models/ ,而不是在myApp/lib/myEngine/addon/models

I don't know if this is intended this way, but this is the only way I found to add model in your in-repo ember-engines . 我不知道这是否是打算这样做的,但这是我发现在回购 余烬引擎中添加模型的唯一方法。


EDIT This will do the trick for the serializers and the transform . 编辑这将为serializerstransform技巧。

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

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