简体   繁体   English

Ember - 我可以将哪些数据类型作为参数传递给 Glimmer 组件?

[英]Ember - What data types can I pass as arguments into a Glimmer Component?

From another template, I can pass arguments to a component, such as:从另一个模板,我可以将参数传递给组件,例如:

<MyComponent @arg1="String" />

I know I could also pass another named object from the template's JS file, but I don't mean to ask about this.我知道我也可以从模板的 JS 文件中传递另一个命名对象,但我并不是要问这个。

My question is, what different data types can be passed in from the template, as a String was in the line above.我的问题是,可以从模板传入哪些不同的数据类型,就像上面一行中的字符串一样。 Can I pass in booleans?我可以传入布尔值吗? What about an array of strings?字符串数组呢? And any special syntax for doing so?以及这样做的任何特殊语法?

Could I for example use {{each}} to loop through an array argument?例如,我可以使用 {{each}} 循环遍历数组参数吗? I guess the alternative's would be either to process through JS, or perhaps work with {{yeild}}.我想另一种选择是通过 JS 处理,或者使用 {{yeild}}。 Thanks.谢谢。

You can pass any primitive, object, or function (which I think is everything in JS) and there are good reasons for doing each of these.您可以传递任何原语、对象或函数(我认为这是 JS 中的所有内容),并且有充分的理由执行这些操作。

Sometimes special helpers are needed to create them:有时需要特殊的助手来创建它们:

@obj={{hash name='Zoey')}}

@bll={{true}}

@arr={{array 1 2 3}}

A function would have to come from somewhere else, though there are helpers like ember-simple-set-helper that let you build it in the template一个函数必须来自其他地方,尽管有像ember-simple-set-helper这样的助手可以让你在模板中构建它

@fnc={{set this.isAwesome true}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM