![](/img/trans.png)
[英]Handle rejected promise when Ember Data hasMany property is accessed by template
[英]Ember Data - Handle API error responses for a hasmany relationship that is accessed through a template
我有一個可以從車把模板通過hasmany關系訪問的模型
models/post.js
export default DS.Model.extend({
comments: DS.hasMany('comment', {async: true}),
});
template/post.hbs
{{#each comment in post.comments}}
我正在使用REST適配器,並且需要處理從車把模板助手執行的GET / posts /:id / comments的成功和失敗響應。
如果這是在控制器/路由中完成的,則可以執行以下操作:
this.store.find('post', post_id)
.then(function(post) {
post.get('comments);
}, function(errors) {
// handle errors
});
通過模板訪問時,我在哪里做相應的工作? 非常感謝您的幫助,言語或智慧!
看起來,此掛鈎在適配器級別可用,但我決定在控制器中顯式加載模型,而不是依賴模板。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.