2016-07-14 96 views
0

我正在玩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 

}); //出口

回答

0

使用_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); 
      }) 

    }); 
    } 
} 
}); 
+0

我用餘燼和queryRecord未在此適配器 –

+0

@RudiWerner實現我想'query'方法返回數組。所以你需要在調用'query'的'then'部分處理這個問題。 –

+0

我是javascript,Ember和emberfire的新手?你能告訴我該怎麼做嗎?謝謝 ! –