首页 > 解决方案 > Ember - 我可以将哪些数据类型作为参数传递给 Glimmer 组件?

问题描述

从另一个模板,我可以将参数传递给组件,例如:

<MyComponent @arg1="String" />

我知道我也可以从模板的 JS 文件中传递另一个命名对象,但我并不是要问这个问题。

我的问题是,可以从模板中传入哪些不同的数据类型,就像上面一行中的字符串一样。我可以传入布尔值吗?字符串数组呢?这样做有什么特殊的语法吗?

例如,我可以使用 {{each}} 循环遍历数组参数吗?我猜另一种选择是要么通过 JS 处理,要么与 {{yeild}} 一起工作。谢谢。

标签: ember.js

解决方案


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.

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

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


推荐阅读