gpt4 book ai didi

ember.js - Elasticsearch和Ember Js

转载 作者:行者123 更新时间:2023-12-03 00:14:55 26 4
gpt4 key购买 nike

我正在尝试将EmberJS与ElasticSearch连接起来。到目前为止,我已经阅读了Ember文档的大部分内容,并为ElasticSearch找到了this adapter

问题是我不知道如何使用它(即配置它,以便当我调用store.save()时,我的模型被发送到ES。

我拥有的ATM是一个新创建的项目,带有Ember生成器(ember new)以及生成的 Controller ,路由器,模型等。我的问题是Ember文档说明了如何customise adapters,但没有说明如何使用它们(否则我错过了该部分)。 ES适配器的文档说:

var App = Em.Application.create();

App.store = DS.Store.create({
revision: 4,
adapter: DS.ElasticSearchAdapter.create({url: 'http://localhost:9200'})
});

这意味着要创建一个商店,而我只能在Ember文档中看到扩展它的方法。此外,我的应用程序中已经有一个商店。

所以问题是:
  • 我是否需要覆盖商店创建,以将其替换为ES之一(以及在何处执行),或者
  • 我是否需要扩展现有的扩展名,在这种情况下,我应该怎么做?

  • 另外,当它说:

    First, load the ember-data/lib/adapters/elasticsearch_adapter.js file in your application.



    应该在哪里以及如何做?

    最佳答案

    关于您的第一个问题

    do I need to override the store creation to replace it with the ES one (and where to do that) OR do I need to extend the existing one, and in this case, how should I do that ?



    在第二部分中,您进入了正确的轨道,在这种情况下,您需要扩展现有的适配器,而不是商店。

    因此,如果您使用的是ember-cli,则根据以下内容:

    What I have ATM is a newly created project with Ember generator (ember new )



    看来您是,所以您的应用程序文件夹结构应如下所示:
    app ->
    adapters(you need to generate/create this)
    components
    controllers
    models
    routes
    serializers
    services
    styles
    templates

    现在我们可以回答:

    how should I do that ?



    如果您还没有(可能还没有)adapters文件夹,则只需运行 ember generate adapter application或创建一个文件夹适配器,然后为该文件夹创建一个文件application.js。

    然后,这最终使我们引出了您的最后一个问题。

    load the ember-data/lib/adapters/elasticsearch_adapter.js file in your application. where and how that should be done ?


    import ElasticSearchAdapter from 'ember-data/lib/adapters/elasticsearch_adapter'

    export default ElasticSearchAdapter.extend({
    })

    现在可能的坏消息是,该适配器可能已过时,因为该存储库的最后一次提交是2012年12月27日。

    关于ember.js - Elasticsearch和Ember Js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37077142/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com