为什么id_cust_fb_cust未定义?
问题描述:
我正在玩emberFire/Ember数据,但无法找到为什么此代码不会工作? var id_cust_ fb_cust总是未定义? 当我看着烬检查查询的工作正常! 我在做什么错?为什么id_cust_fb_cust未定义?
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
fixit: function() {
var teller = 11;
var _this = this;
var strTeller = teller.toString();
_this.store.findRecord('address',strTeller).then(function(address){
var id_cust_presta_addr = address.get('id_customer');
console.log('Id Customer Presta in address is :' + id_cust_presta_addr);
_this.store.query('customer', {
orderBy: 'id_customer',
equalTo: id_cust_presta_addr
}).then(function(customer){
var id_cust_fb_cust = customer.get('email');
console.log('Id Customer Presta in CUSTOMER is :' + id_cust_fb_cust + 'voor : ' + id_cust_presta_addr);
})
});
} //fixit
} // actions
}); //出口
答
使用_this.store.queryRecord
,而不是_this.store.query
UPDATE
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
fixit: function() {
var teller = 11;
var _this = this;
var strTeller = teller.toString();
_this.store.findRecord('address',strTeller).then(function(address){
var id_cust_presta_addr = address.get('id_customer');
console.log('Id Customer Presta in address is :' + id_cust_presta_addr);
_this.store.query('customer', {
orderBy: 'id_customer',
equalTo: id_cust_presta_addr
}).then(function(customers){
//HERE : customers is array
var customer = customers.objectAt(0);
var id_cust_fb_cust = customer.get('email');
console.log('Id Customer Presta in CUSTOMER is :' + id_cust_fb_cust + 'voor : ' + id_cust_presta_addr);
})
});
}
}
});
我用余烬和queryRecord未在此适配器 –
@RudiWerner实现我想'query'方法返回数组。所以你需要在调用'query'的'then'部分处理这个问题。 –
我是javascript,Ember和emberfire的新手?你能告诉我该怎么做吗?谢谢 ! –