简体   繁体   English

使用yield的Ember渲染组件

[英]Ember rendering component using yield

I have a my-component1.js defined as below; 我有一个my-component1.js定义如下;

export default Ember.Component.extend({ 
prop1: 'abc'
})

The corresponding template my-component1.hbs is as below; 相应的模板my-component1.hbs如下所示;

{{#my-yield-component2}}
    {{my-other-component3 field=(my-helper prop1)}}
{{/my-yield-component2}}

So I want to display/render my-other-component3 inside my-yield-component2 (as I am using yield) 所以我想在my-yield-component2内部显示/渲染my-other-component3(因为我正在使用yield)

Inside my-yield-component2 , I have the following; my-yield-component2内部,我有以下内容;

<div>My component with yield</div>
<div>{{yield}}</div>

My question is how do I pass/get access to "prop1" which is actually defined in my-component1, but because I am using yield, it would be rendered in my-yield-component2 So I want to know how to pass "prop1" ? 我的问题是我如何通过/获取对在my-component1中实际定义的“ prop1”的访问权限,但是由于我使用的是yield,它将在my-yield-component2中呈现,所以我想知道如何通过“ prop1” ?

There is nothing wrong with the way prop1 value of my-component1 is passed to my-other-component3 . my-component1 prop1值传递给my-other-component3的方式没有任何问题。 The context within my-component1 's template file is my-component1 itself; my-component1的模板文件中的上下文是my-component1本身; hence prop1 will be passed from my-component1 to my-other-component3 even if my-other-component3 is rendered within my-yield-component2 . 因此,即使将my-other-component3渲染在my-yield-component2 prop1也将从my-component1传递到my-other-component3 my-yield-component2 Please take a look at the following twiddle that illustrates what I explained so far works smoothly. 请看一下下面的旋转方式 ,该旋转方式说明了我到目前为止所解释的工作顺利进行的过程。

Regarding value passing from my-yield-component2 to my-other-component3 is another story; 关于从my-yield-component2传递到my-other-component3是另一回事。 where you need to yield sth. 需要yield地方 from the template of my-yield-component2 and pass it to my-other-component3 as follows: my-yield-component2的模板中将其传递给my-other-component3 ,如下所示:

{{#my-yield-component2 as |valueToYield|}}
    {{my-other-component3 field=(my-helper prop1) otherField=valueToYield}}
{{/my-yield-component2}}

I have already provided a working twiddle of what I explained above in one of your previous questions. 我已经提供了工作摆弄什么,我在上面解释一个你以前的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM