2017-04-16 47 views
0

調用數據存儲的findRecord()函數時出現奇怪的錯誤。下面是一個路由的內部函數調用,findRecord()返回錯誤,但記錄正確返回

return this.get('store').findRecord('restaurant', params.restaurant_id); 

這裏是我得到的錯誤,

vendor-6605726….js:10 Error while processing route: admin.restaurants.show e.getRecord is not a function TypeError: e.getRecord is not a function 

vendor-6605726….js:8 TypeError: e.getRecord is not a function 

最奇怪的是,該功能的工作,因爲它應該,因爲我可以看到使用燼檢查該查詢正確執行並返回正確的記錄。我有一個調用findAll()的索引路由,它不會拋出任何錯誤。我正確地格式化我的JSON我相信,所以我不知道這可以做什麼。

這裏是JSON,

{"data":[{"type":"restaurants","id":1,"attributes":{"user_id":1,"name":"###########","address":"","phone":"##########","website":"##########","created_at":"2017-03-19 20:42:02","updated_at":"2017-03-19 20:42:02","description":"###########"}}]} 
+0

你只有在生產中才得到這個嗎?因爲在開發中你會得到一個更好的錯誤。 – Lux

回答

0

最近我有同樣的問題。您的API返回的JSON有效負載很可能未正確格式化。請記住,findRecord()預計要返回一個對象,而不是一個數組:

{"data": {}} 

{"data": []} 

仔細檢查DevTools看到你的API返回給客戶端 - 確保它不數組。

相關問題