![](/img/trans.png)
[英]How to access parent properties from a child view created using `createElement`
[英]Accessing parent view's properties from a child one(using yield helper)
有沒有一種方法可以從產生的組件訪問父視圖的屬性。 這是我正在嘗試做的jsbin: http ://jsbin.com/buyiq/1/
所以我的組件定義為:
App.QuestionViewComponent = Ember.Component.extend({
layoutName: "components/quesiton-view",
templateName: "components/confirm-delete",
actions: {
}
});
<script type="text/x-handlebars" data-template-name="components/confirm-delete">
<div>Are you sure you want to delete {{question.name}}?</div>
</script>
<script type="text/x-handlebars" data-template-name="components/quesiton-view">
<div>{{question.name}}</div>
{{yield}}
</script>
在確認刪除組件中,我想訪問包含父組件的問題屬性(question-view)。 我該如何實現?
謝謝迪
的上下文中components/confirm-delete
,在傳遞的每個問題對象each
。
因此,只需將其更改為:
<script type="text/x-handlebars" data-template-name="components/confirm-delete">
<div>Are you sure you want to delete {{name}} ?</div>
</script>
這是更新的jsbin
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.