mardi 22 mars 2016

KnockoutJS, style binding with a 2D array?

So I am working with a JSON object of CSS attributes/divs, something like:

"#myDiv": {
    "position": "absolute",
    "max-height": "225px"
  },

And I am binding this object to a div using KnockoutJS's style binding:

<!-- ko with: $root.Styles['#myDiv'] -->
     <div data-bind="style:{
         position: position,
         maxHeight: $data['max-height']
       }"></div>
<!-- /ko -->

Position binds fine, and any other properties that do not have to be accessed explicitly are OK as well. Is it possible to bind something like $data['max-height'] within a KnockoutJS style binding?

*I'd also like to note that I can succesfully bind $data['max-height'] to a text field, but it always fails with a syntax error when binding a style.

Thoughts? :)



KnockoutJS, style binding with a 2D array?

Aucun commentaire:

Enregistrer un commentaire