[英]return an object value from ember helper and passing through hbs template
can ember return an object value from helper, and if that can how to passing to hbs template for component.可以从 helper 返回一个对象值,如果可以的话,如何传递给组件的 hbs 模板。 Exactly I just wanna do this.
正是我只想这样做。
import Ember from 'ember';
export function someHelper(params/*, hash*/) {
switch(params) {
case 'a':
return { a:21,b:22 }
break;
case 'b':
return { a:21,b:20 }
break;
default:
return { a:2,b:211 }
}
}):
And this is a hbs template这是一个 hbs 模板
<p>{{some-helper object.foo}} </p>
how to get the value from ember helper that return object to my hbs template??如何从将对象返回到我的 hbs 模板的 ember 助手获取值?
You can use the get
helper provided by Ember;可以使用 Ember 提供的
get
助手; see the api reference .请参阅api 参考。 I modified your helper and used
get
helper in the following twiddle to illustrate you the usage.我修改了你的 helper 并在下面的twiddle 中使用了
get
helper 来说明用法。 By the way, params
passed to helper is an array so I got the first item (0 index) from the array for the switch
case you have provided.顺便说一下,传递给 helper 的
params
是一个数组,所以我从您提供的switch
案例的数组中获得了第一项(0 索引)。 See application.hbs
to see get
helper in action.请参阅
application.hbs
以查看get
helper 的运行情况。 My best regards.我最诚挚的问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.