EmberJS,带有 "as" 块的助手
EmberJS, Helper with an "as" block
我有一个对象,然后我有一个使用对象的装饰器和 returns 对象的人性化表示。
例如:
object = { id: "XXX1", detail: "XXX2" }
decoratedObject { title: "The Red Building", detail: "Has 101 stories" }
我想在模板中使用装饰器:
{{#decorator-helper object as |decoratedObject|}}
<h1>{{decoratedObject.title}}</h1>
<p>{{decoratedObject.detail}}</p>
{{/decorator-helper}}
我该怎么做?
你应该为此使用一个组件。
通常情况下,如果您想使用辅助函数来计算其他值,则应使用辅助函数,如下所示:
{{my-component value=(my-helper val)}}
如果你想使用块语法,你应该使用组件。
据我所知,你不能在助手的帮助下做到这一点。为什么不在控制器或基于对象的组件上定义一个名为 decoratedObject
的计算 属性?
decoratedObject: Ember.computed('object', {
get() {
// Build your decorated object and return it
return decoratedObject;
}
})
这将使您的装饰对象在您的模板中可用,并在对象更改时动态重建它。
我有一个对象,然后我有一个使用对象的装饰器和 returns 对象的人性化表示。
例如:
object = { id: "XXX1", detail: "XXX2" }
decoratedObject { title: "The Red Building", detail: "Has 101 stories" }
我想在模板中使用装饰器:
{{#decorator-helper object as |decoratedObject|}}
<h1>{{decoratedObject.title}}</h1>
<p>{{decoratedObject.detail}}</p>
{{/decorator-helper}}
我该怎么做?
你应该为此使用一个组件。
通常情况下,如果您想使用辅助函数来计算其他值,则应使用辅助函数,如下所示:
{{my-component value=(my-helper val)}}
如果你想使用块语法,你应该使用组件。
据我所知,你不能在助手的帮助下做到这一点。为什么不在控制器或基于对象的组件上定义一个名为 decoratedObject
的计算 属性?
decoratedObject: Ember.computed('object', {
get() {
// Build your decorated object and return it
return decoratedObject;
}
})
这将使您的装饰对象在您的模板中可用,并在对象更改时动态重建它。