我想創建一個Ember.js應用程序第一次使用RESTful後端。我一直在使用從我的服務器呈現的HTML,因此我是一個新手燼。 我有一個基於所有者ID獲取餐廳的查詢,然後在標題欄中顯示名稱。Ember數據從休息URL不呈現
LiveKitchen.RestaurantController = Ember.ObjectController.extend({
needs : 'login'
});
LiveKitchen.RestaurantRoute = Ember.Route.extend({
model: function() {
console.log(this.controllerFor('login').get('user_id'));
console.log('Fetching Restaurants ' + this.store.find('restaurant', {owner_id : this.controllerFor('login').get('user_id')}));
var res = this.store.find('restaurant', {owner_id : this.controllerFor('login').get('user_id')});
// restaurant.tables = this.store.find('table', {restaurant_id : restaurant.mongo_id});
console.log('Restaurant ' + res);
return res.objectAt(0);
// return restaurant;
}
});
我已驗證了使用調試器的響應,並且看到json數據正確返回。然而,我的模板
<script type="text/x-handlebars" data-template-name="restaurant">
<small>
<i class="icon-leaf"></i>
{{name}}
</small>
</script>
沒有在頁面上打印的名稱。
你可以請我幫助我如何調試,並找出爲什麼數據不呈現?由於沒有錯誤,我無法找出接下來要採取的步驟。
'this.store.find('restaurant')'返回餐廳模型的多個實例嗎? – NicholasJohn16
最初,我以{「restaurant」:{「name」:「SomeName」,...}}的形式返回了一家餐廳,該餐廳無法使用。所以我認爲它可能會期待很多,並開始返回{「餐館」:[{「name」:「SomeName:,...}]} – Manoj
我嘗試了其他的東西,而不是使用owner_id,我用對象的ID並使用this.store.find('restaurant',id),然後名稱來了。雖然從兩種情況返回的數據是相同的從REST API,燼數據似乎期望不同的結果? – Manoj