ember.js - Ember - 我可以将哪些数据类型作为参数传递给 Glimmer 组件?
问题描述
从另一个模板,我可以将参数传递给组件,例如:
<MyComponent @arg1="String" />
我知道我也可以从模板的 JS 文件中传递另一个命名对象,但我并不是要问这个问题。
我的问题是,可以从模板中传入哪些不同的数据类型,就像上面一行中的字符串一样。我可以传入布尔值吗?字符串数组呢?这样做有什么特殊的语法吗?
例如,我可以使用 {{each}} 循环遍历数组参数吗?我猜另一种选择是要么通过 JS 处理,要么与 {{yeild}} 一起工作。谢谢。
解决方案
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}}
推荐阅读
- python - 如何使用条件更改列表的字典
- c++ - 我该如何完成这个例子?
- powerbi - 在 Power BI 中查找 Last hour, Last 'x' minute/s 详细信息(来自 SQL Server 的数据)
- python - 如何在 Google Colab 中使用 matplotlib 避免格式错误?
- javascript - 使用 NodeJS 从 AWS S3 下载 pdf 文件
- r - 模型构建并停留在 R 中的错误消息上
- python - n-dim 球面积分与 nquad
- quarkus - Quarkus Metrics - 拦截指标端点
- python - ValueError: Input 0 is in compatible with layer conv2d_42: expected ndim=4, found ndim=2 for a numeric dataset
- shopify - 如何在我的 Shopify 应用安装时自动将文件(部分/片段)添加到用户的 Shopify 主题