[英]In Ember can you overwrite component functions using the component helper?
Still pretty new to Ember.对 Ember 来说还是很新的。 I am trying to use the
component
Ember helper to overwrite a function on the component.我正在尝试使用
component
Ember 助手来覆盖组件上的函数。
My component looks like:我的组件看起来像:
Ember.Component.extend({
...
getValue() {...}
...
});
I have another component with a template that looks like:我有另一个带有模板的组件,如下所示:
<div>
{{component myComponentName getValue=(action myCustomGetValue)}}
</div>
I would imagine that this would overwrite the getValue
function from the original component, but it does not.我想这会覆盖原始组件的
getValue
函数,但事实并非如此。 Is this possible using this helper to do this?这可以使用这个助手来做到这一点吗? Or am I going about this the wrong way?
还是我以错误的方式解决这个问题?
Yes, you can pass function references to component
helpers in Emberjs.是的,您可以将函数引用传递给 Emberjs 中的
component
助手。
You can call your component through component
helper like:您可以通过
component
助手调用您的组件,例如:
{{component "my-component" getValue=(action "myCustomGetValue")}}
in which case you should define the custom action in your parent component or controller like:在这种情况下,您应该在父组件或控制器中定义自定义操作,例如:
actions: {
myCustomGetValue(){
return "my custom value";
}
}
You can take a look at this twiddle for this usage.您可以查看此 twiddle以了解此用法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.