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

Allow functions as arguments for ivh-treeview attributes/filter methods #149

Open
diimpp opened this issue Aug 15, 2016 · 1 comment
Open

Comments

@diimpp
Copy link

diimpp commented Aug 15, 2016

To avoid even further data massaging, it would be cool to have "virtual" attributes for id, label, children, filter by allowing function instead of attribute names.

My prime usecase is a translation array at the label property,
so my data looks like this

{id:1, children: [1,2], label: {'en_GB': 'label', 'de_DE': 'Etikett'}}

With API like this

         <div ivh-treeview="bag"
              ivh-treeview-label-attribute="label()">
         </div>
         /**
          * Get the label for `node`
          *
          * Abstracts away the need to know the actual label attribute in
          * templates.
          *
          * @param {Object} node A tree node
          * @return {String} The node label
          */
         trvw.label = function(node) {
           +++ return node[localOpts.labelAttribute()]; // Do it conditionally on function
           --- return node[localOpts.labelAttribute];
         };

And it still should be filterable. So something similar required there too.

All code snippets are only to illustrate my point, they certainly don't attempt to show way to do it.

Regards.

@jtrussell
Copy link
Contributor

jtrussell commented Aug 17, 2016

I think this is something we could support in version 1 by leaving those things as variables instead of functions and just watching for updates. Or perhaps better, just re-flattening our local options whenever they're asked for.

Happy to investigate when available but we'd be certainly open to a PR that doesn't break backwards compatibility.

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

No branches or pull requests

2 participants