Willem de Wit
Willem de Wit

Reputation: 8732

Ember opposite of positionalParams

In an Ember Component it is possible to define a positionalParams property so that parameters passed as positional params become available as properties. E.g:

let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
  positionalParams: ['name', 'age']
});

when it is invoked: {{my-component "John" 38}} the property name has the value John and de property age has the value 38.

I would like to have the opposite behavior but I cannot find whether this is possible. The behavior I'm looking for is like following:

Instead of passing a number of positional params ({{my-comp param1 param2}}) I would like to pass an array property ({{my-comp positionalArguments=myArray}}) because it can be of a dynamic size.

I'm not only looking for this behavior at components, but also helpers: {{ concat firstName " " lastName }} should become {{ concat positionalArguments=myArray }}. The helper should get the same params-array as first argument in both cases.

Upvotes: 0

Views: 214

Answers (1)

ykaragol
ykaragol

Reputation: 6221

UPDATE After my misunderstood is resolved:

You want to have a spread operator. You may look this discussions 1, 2. For now, you can get the array and do the assignment at init. Also have a look at this SO discussion.

OLD Answer

So don't use array brackets in your positional parameter definition:

let MyComponent = Ember.Component.extend;
MyComponent.reopenClass({
  positionalParams: 'myparams'
});

Use it like that:

{{my-component 2 'a' 'b'}}
{{my-component 2 'a' 'b' 4 'c' 7}}

Upvotes: 1

Related Questions