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