有没有办法可以从已生成的组件访问父视图的属性。这是我试图做的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>
在确认删除组件中,我想访问包含父组件的问题属性(问题视图)。我怎样才能做到这一点?
谢谢, DEE
答案 0 :(得分:1)
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>
Here是更新的jsbin