在 Ember 中,您可以使用组件助手覆盖组件功能吗?
In Ember can you overwrite component functions using the component helper?
对 Ember 还是很陌生。我正在尝试使用 component
Ember 助手来覆盖组件上的函数。
我的组件看起来像:
Ember.Component.extend({
...
getValue() {...}
...
});
我有另一个组件,其模板如下所示:
<div>
{{component myComponentName getValue=(action myCustomGetValue)}}
</div>
我想这会覆盖原始组件的 getValue
函数,但事实并非如此。这可能使用这个助手来做到这一点吗?还是我做错了?
是的,您可以将函数引用传递给 Emberjs 中的 component
助手。
您可以通过 component
帮助程序调用您的组件,例如:
{{component "my-component" getValue=(action "myCustomGetValue")}}
在这种情况下,您应该在父组件或控制器中定义自定义操作,例如:
actions: {
myCustomGetValue(){
return "my custom value";
}
}
这个用法你可以看一下this twiddle。
对 Ember 还是很陌生。我正在尝试使用 component
Ember 助手来覆盖组件上的函数。
我的组件看起来像:
Ember.Component.extend({
...
getValue() {...}
...
});
我有另一个组件,其模板如下所示:
<div>
{{component myComponentName getValue=(action myCustomGetValue)}}
</div>
我想这会覆盖原始组件的 getValue
函数,但事实并非如此。这可能使用这个助手来做到这一点吗?还是我做错了?
是的,您可以将函数引用传递给 Emberjs 中的 component
助手。
您可以通过 component
帮助程序调用您的组件,例如:
{{component "my-component" getValue=(action "myCustomGetValue")}}
在这种情况下,您应该在父组件或控制器中定义自定义操作,例如:
actions: {
myCustomGetValue(){
return "my custom value";
}
}
这个用法你可以看一下this twiddle。