如何在ember.js 2.0.0中使用emberfire查询名为equalTo xyz的所有项目的firebase数据库? [英] How to use emberfire to query a firebase db for all items with name equalTo xyz in ember.js 2.0.0?

查看:134
本文介绍了如何在ember.js 2.0.0中使用emberfire查询名为equalTo xyz的所有项目的firebase数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ember.js和firebase的新手。
我一直在试图做一些事情,需要我去查询一个匹配定义的键的键。
$ b

根据 guides.emberjs.com ,下面的例子应该工作:

  this.store.query('person',{filter:{name:'Peter'}})。then(function (peters){
//用`peters`做些事
});

但事实并非如此。显然是因为我正在使用emberfire插件。
经过几个小时的搜索,没有明确的解决方案。

emberfire docs 讨论可用的参数。


参数


$ b

orderBy - 字符串 - 属性...





。 , Null - 创建一个查询,其中包含匹配指定值的子元素。


现在举个例子...

  // app / routes / dinosaurs.js 
导出默认值Ember.Route.extend({
model:function(){
return this.store.find('dinosaur',{
orderBy:'height',
limitToLast:10,
startAt:5
});
}
});

尽管未显示如何使用equalTo。
我已经测试了所有这些,但是我不明白 equalTo 是如何工作的。

是关于这个的其他解决方案,但他们都在v2.0.0之前。所以我不认为他们会在v2.0.0后工作。



Ember.js调试信息:

  DEBUG:------------------------------- 
DEBUG:Ember: 2.0.0
DEBUG:Ember数据:2.0.0
DEBUG:Firebase:2.3.1
DEBUG:EmberFire:1.6.0
DEBUG:jQuery:1.11.3
DEBUG:-------------------------------

正在使用的数据库: https:// shoutoutdb.firebaseio。 com / users



我不完全了解equalTo应该如何在这里工作,但我也没有得到任何线索。希望这里有人愿意帮忙。

如果您认为这个问题需要改进,请提问。我已经详细了,以及我认为我应该。

在此先感谢。 :)

编辑:
我尝试使用的代码:

 <$ c 
函数(数据){
//用数据
完成的工作} $($'$'$'$'
);

我也尝试了多个不同的代码。没有任何工作,所以我不认为它甚至在这里值得一提。

解决方案

使用查询功能,您可以将 orderByChild equalTo 来获得想要的结果:

  ref.child('people')。orderByChild('name')。equalTo('Peter')。on('value',...); 

等同于的web API参考以及

因此,在EmberFire中,这将转化为以下内容:



pre $ this.store.query('person',{orderBy:'name',equalTo:'Peter'});


I'm new to ember.js and firebase. I've been trying to make something that needs me to query the DB for a key matching a defined value.

According to guides.emberjs.com, the following example should work:

this.store.query('person', { filter: { name: 'Peter' } }).then(function(peters) {
  // Do something with `peters`
});

But it doesn't. Apparently because I'm using the emberfire addon. After literally hours of googling, there was no clear solution.

The emberfire docs talk about the available arguments.

Arguments

orderBy - String - The property ...
.
.
.

equalTo - String, Number, Null - Creates a query which includes children which match the specified value.

And present an example...

// app/routes/dinosaurs.js
export default Ember.Route.extend({
  model: function() {
    return this.store.find('dinosaur', {
      orderBy: 'height',
      limitToLast: 10,
      startAt: 5
    });
  }
});

Although without showing how to use 'equalTo'. I've tested all of them, but I failed to understand how equalTo works.

There are other solutions on SO about this, but they are all pre-v2.0.0. So I don't think they would work post v2.0.0.

Ember.js debug info:

DEBUG: -------------------------------
DEBUG: Ember      : 2.0.0
DEBUG: Ember Data : 2.0.0
DEBUG: Firebase   : 2.3.1
DEBUG: EmberFire  : 1.6.0
DEBUG: jQuery     : 1.11.3
DEBUG: -------------------------------

The database in use: https://shoutoutdb.firebaseio.com/users

I don't fully understand how equalTo should work here, but I'm not getting any clue either. Hopefully someone here will be willing to help.

If you think the question needs any kind of improvement, kindly ask. I've detailed it as well as I thought I should.
Thanks in advance. :)

EDIT: Code I tried to use:

$E.store.find('user',{name:'Alpha'}).then(
    function (data) {
       //stuff done with the data
    }
);

I also tried multiple different versions around this code. Nothing worked, so I don't think it's even worth mentioning them here.

解决方案

Using the querying capabilities you can combine orderByChild and equalTo to get the desired result:

ref.child('people').orderByChild('name').equalTo('Peter').on('value', ...);

There is an example in the web API reference for equalTo and in the Web guide on complex queries.

So, in EmberFire, this would translate to the following:

this.store.query('person', { orderBy: 'name', equalTo: 'Peter' });

这篇关于如何在ember.js 2.0.0中使用emberfire查询名为equalTo xyz的所有项目的firebase数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆