vendredi 13 novembre 2015

Check what attributes have been assigned to component in Emberjs

I wrote a component to display a select modal dialog.

{{m-modal-select value=valList valuePool=possibleValueList}}

This is a multi-select component, valuePool is the candidate list, value is the selected list. Now I want to support both multi-select and single-select within this component, when it is single mode, the code should be like this:

{{m-modal-select singleValue=selectedOne valuePool=possibleValueList}}

I wish the component itself can recognize whether it is in single or multiple mode by watching which attribute(value or singleValue) is assigned to it.

I don't know how to achieve this in component js.

Additionally, I also wonder if there is a function to get all assigned attributes' names in component. For the above two examples, it would be like below:

this.get('assignedAttrNames');  

//the first one 
// ['value', 'valuePool']

//the second one
// ['singleValue', 'valuePool']

Aucun commentaire:

Enregistrer un commentaire