ember 组件中的动态参数

Dynamic params in ember component

我有一个组件,在渲染它时传递了参数。它将有动态参数,所以我不能通过它的名字准确地得到它。找了很多帖子都没找到合适的

Application.hbs

{{small-button type="small" edges="curved"}}

small-button.js

Ember.Component.extend({
 tagName: "button",
 didInsertElement: function(){
   //need to get the dynamic params
 }
});

我不知道参数密钥。我怎样才能从我的组件中获取所有参数 button

提前致谢。

如果可能,请考虑此用例的任何其他替代方案。现在我只为你而不是其他人建议 this.attrs

didInsertElement: function(){
   //need to get the dynamic params
   console.log(' Params keys ',Object.keys(this.attrs));
   console.log(' Param values ', Object.values(this.attrs));
 }

读这个 - https://locks.svbtle.com/to-attrs-or-not-to-attrs

So, why shouldn’t you use attrs in Classic Components? Because in Classic Components attrs already existed, and is used internally to manage component bindings and might not be exactly what you need. While you should be mostly fine using it for actions, you’ll have problems if you use it for attributes, so it’s easier to use the current APIs than to keep this in mind.