Binding several attributes to the same element

blueFast

I am trying to do something like this:

<a href="#/{{unbound goto}}" {{bind-attr class=":menu-entry-text :nowrap active:selected-menu-entry-text"}} {{bind-attr id="active:active-nav:inactive-nav"}} {{bind-attr data-goto="goto"}}>

But only the first attribute (class) gets set: id and data-goto are not defined. Is it possible to set several attributes with bind-attr in the same element? How?

Peter Brown

Yes you can bind several attributes at once by either using multiple bind-attr helpers like in your example, or just putting all the attributes in a single bind-attr helper. You have an issue in your example though, which is why things aren't working as expected.

The "value if true" form that you're using for the class attribute cannot be applied to other types of attributes. All other attributes must be bound to a dynamic property on the controller. For example, if you had a controller that looked like this:

App.MyController = Ember.ObjectController.extend({
  myId: function() {
    if (this.get("active") === true) {
      "active-nav"
    } else {
      "inactive-nav"
    }
  }.property("active")
});

Then you would bind that like so:

<a href="#/{{unbound goto}}" {{bind-attr id="myID"}}>

Just a side note on that example, it's probably a code smell if you have a dynamic ID for an HTML element. IDs are supposed to uniquely identify a single element and I wouldn't expect them to change. It seems like a class would be a better fit for this use case.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

'itemprop' and 'rel' attributes on same element

From Dev

append the same element to several sublists in python

From Dev

How to create an root element with several prefix:namespaces attributes in XSLT

From Dev

Element with attributes with the same name from two namespaces

From Dev

LinQ GroupBy on nested element with same attributes

From Dev

How to declare several stylable attributes with the same name for different tags?

From Dev

Best way for several classes to share the same attributes in C#

From Dev

Make several classes have the same attributes without inheritance

From Dev

Dart data binding from a parent custom element to attributes of a child custom element

From Dev

Marklogic query based on values of multiple attributes of the same element

From Dev

Add several attributes to a NSMutableAttributedString

From Dev

jQuery load in event handler - how to manipulate several attributes of event element when load is complete?

From Dev

knockoutjs 3.4 cannot apply binding to the same element again

From Dev

Binding List to several ComboBoxes

From Dev

Binding attributes using Directives

From Dev

Binding functions with attributes

From Dev

Binding attributes using Directives

From Dev

Use WinJS to bind attributes of HTML element and how to prevent knockout from binding on HTML elements ?

From Dev

Pandas histogram grouped by several attributes

From Dev

Define ToolTip with several binding properties

From Dev

Binding to arbitrary or nonstandard attributes in Aurelia

From Dev

Shortcut for WPF text in Binding attributes

From Dev

Binding multiple expressions in custom attributes

From Dev

polymer data binding through attributes

From Dev

binding attributes and properties in polymer 1.0

From Dev

Binding some attributes of object to data

From Dev

Polymer data binding with Javascript and attributes

From Dev

Is there a way to check two different by.css() attributes in the same element() check in protractor?

From Dev

Is there a way to check two different by.css() attributes in the same element() check in protractor?

Related Related

  1. 1

    'itemprop' and 'rel' attributes on same element

  2. 2

    append the same element to several sublists in python

  3. 3

    How to create an root element with several prefix:namespaces attributes in XSLT

  4. 4

    Element with attributes with the same name from two namespaces

  5. 5

    LinQ GroupBy on nested element with same attributes

  6. 6

    How to declare several stylable attributes with the same name for different tags?

  7. 7

    Best way for several classes to share the same attributes in C#

  8. 8

    Make several classes have the same attributes without inheritance

  9. 9

    Dart data binding from a parent custom element to attributes of a child custom element

  10. 10

    Marklogic query based on values of multiple attributes of the same element

  11. 11

    Add several attributes to a NSMutableAttributedString

  12. 12

    jQuery load in event handler - how to manipulate several attributes of event element when load is complete?

  13. 13

    knockoutjs 3.4 cannot apply binding to the same element again

  14. 14

    Binding List to several ComboBoxes

  15. 15

    Binding attributes using Directives

  16. 16

    Binding functions with attributes

  17. 17

    Binding attributes using Directives

  18. 18

    Use WinJS to bind attributes of HTML element and how to prevent knockout from binding on HTML elements ?

  19. 19

    Pandas histogram grouped by several attributes

  20. 20

    Define ToolTip with several binding properties

  21. 21

    Binding to arbitrary or nonstandard attributes in Aurelia

  22. 22

    Shortcut for WPF text in Binding attributes

  23. 23

    Binding multiple expressions in custom attributes

  24. 24

    polymer data binding through attributes

  25. 25

    binding attributes and properties in polymer 1.0

  26. 26

    Binding some attributes of object to data

  27. 27

    Polymer data binding with Javascript and attributes

  28. 28

    Is there a way to check two different by.css() attributes in the same element() check in protractor?

  29. 29

    Is there a way to check two different by.css() attributes in the same element() check in protractor?

HotTag

Archive