簡體   English   中英

從子視圖訪問父視圖的屬性(使用yield helper)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM