Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Attributes dash vs underscore modifications #99

Open
dancrew32 opened this issue Aug 26, 2014 · 0 comments
Open

Data Attributes dash vs underscore modifications #99

dancrew32 opened this issue Aug 26, 2014 · 0 comments

Comments

@dancrew32
Copy link

I'm in the process of converting some interpolated data attributes to use bindonce's bo-attr-data* and noticed something unexpected:

var bar = {
  foo_thing: 'testing1',
  foo_other: 'testing2'
};

Say there are data attributes written with underscores, which (I believe) is valid HTML:

<ANY data-foo_thing="{{ bar.foo_thing }}" data-foo_other="{{ bar.foo_other }}"></ANY>

So in the directive you can go:

return function($scope, $element, $attrs) {
    var element_data = $element.data(); // gather all data attributes in one pass
    console.log(element_data.foo_thing); // 'testing1'
    console.log(element_data.foo_other); // 'testing2'
};

When converting code like this to use bindonce's bo-attr, it is replacing underscores with dashes.
Think it might be this line: https://github.com/Pasvaz/bindonce/blob/master/bindonce.js#L198

<ANY bo-attr bo-attr-data-foo_thing="bar.thing" bo-attr-data-foo_other="bar.other"></ANY>

becomes

<ANY bo-attr bo-attr-data-foo_thing="bar.foo_thing" bo-attr-data-foo_other="bar.foo_other"
data-foo-thing="testing1" data-foo-other="testing2"></ANY>

which results in:

return function($scope, $element, $attrs) {
    var element_data = $element.data(); // gather all data attributes in one pass
    console.log(element_data.foo_thing); // undefined
    console.log(element_data.foo_other); // undefined

   // actual data, camelCased
   console.log(element_data.fooThing); // testing1
   console.log(element_data.fooOther); // testing2
};

It would be nice if the format of the data attributes were preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant