I'm not sure how you would data-bind an element's class attribute
right now. (again, still learning Agility) The closest thing I can
see would be to use a method similar to this snippet from the docs:
var icon = $$({path:url}, '<p>Image src from model: <img data-
bind="src=path"/></p>');
I suppose this would work if you wanted to replace the entire
attribute value. Typically though you probably only want to add/
remove one or two classes rather than all of them.
I think what I would be looking for is the ability to associate a call
to toggleClass() with changes to the data. Consider the use case of a
multiple choice question with an "other" answer. You may want to use
a radio group with options A, B, C and Other. Along with this you
might have a textbox to allow the user to enter their "other" answer.
By default you may have a .hidden class assigned to this textbox. If
the user selects the Other radio option, you would want to toggle that
class off the textbox. If they change their mind and then click A, B,
or C then you would want to toggle the class back on the textbox so it
hides again.
This behavior is seems like its already possible with agility just by
attaching a handler to the change event, evaluating the data and
executing toggleClass on the proper element. A little bit more
sophisticated, but maybe more logical approach would be to have user
defined properties that react to changes in the model and then adjust
the styling based on changes to those properties. In the use case
above, we might have a boolean isOther property that watches for model
changes. Then we would toggle the .hidden class based on whether
isOther is true or false. This might be more complicated than
necessary, but it would allow for more advanced rules on the data-
binding.
As for the avatar example, I wouldn't want to use css classes at all.
I would prefer to databind the background image url in an inline
style.
In general, I can see the reasoning behind agility dynamically
creating css classes from the style definitions but this is not a
feature I see myself using much. If I'm going to adjust something in
the look and feel that's highly specific to an instance of an object
then inline styling is probably ok.
On May 17, 6:14 pm, Tom Lackner <
lack...@gmail.com> wrote:
> Can't you already use data-bind to set an element's class attribute?
>
> Also, how would you use external classes to set an element's
> background-image to a user's avatar photo from a Rest API? Just an example,
> but things like that are a common use case..
>
>
>
>
>
>
>
> On Thu, May 17, 2012 at 7:08 PM, Artur Adib <
artura...@gmail.com> wrote:
> ...
>
> read more »