问题描述
我是ember.js和firebase的新手。
我一直在试图做一些事情,需要我去查询一个匹配定义的键的键。
$ b
根据,下面的例子应该工作:
this.store.query('person',{filter:{name:'Peter'}})。then(function (peters){
//用`peters`做些事
});
但事实并非如此。显然是因为我正在使用emberfire插件。
经过几个小时的搜索,没有明确的解决方案。
讨论可用的参数。
现在举个例子...
// 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:-------------------------------
正在使用的数据库:
我不完全了解equalTo应该如何在这里工作,但我也没有得到任何线索。希望这里有人愿意帮忙。
如果您认为这个问题需要改进,请提问。我已经详细了,以及我认为我应该。
在此先感谢。 :)
编辑:
我尝试使用的代码:
<$ c
函数(数据){
//用数据
完成的工作} $($'$'$'$'
);
我也尝试了多个不同的代码。没有任何工作,所以我不认为它甚至在这里值得一提。
使用查询功能,您可以将 orderByChild
和 equalTo
来获得想要的结果:
ref.child('people')。orderByChild('name')。equalTo('Peter')。on('value',...);
以及。 因此,在EmberFire中,这将转化为以下内容: 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: 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. And present an example... Although without showing how to use 'equalTo'.I've tested all of them, but I failed to understand how 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: 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. EDIT:Code I tried to use: 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 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: 这篇关于如何在ember.js 2.0.0中使用emberfire查询名为equalTo xyz的所有项目的firebase数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
pre $ this.store.query('person',{orderBy:'name',equalTo:'Peter'});
this.store.query('person', { filter: { name: 'Peter' } }).then(function(peters) {
// Do something with `peters`
});
// app/routes/dinosaurs.js
export default Ember.Route.extend({
model: function() {
return this.store.find('dinosaur', {
orderBy: 'height',
limitToLast: 10,
startAt: 5
});
}
});
equalTo
works.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: -------------------------------
Thanks in advance. :)$E.store.find('user',{name:'Alpha'}).then(
function (data) {
//stuff done with the data
}
);
orderByChild
and equalTo
to get the desired result:ref.child('people').orderByChild('name').equalTo('Peter').on('value', ...);
this.store.query('person', { orderBy: 'name', equalTo: 'Peter' });