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

Add option for searching through nested properties #16

Open
levacic opened this issue Dec 11, 2014 · 1 comment
Open

Add option for searching through nested properties #16

levacic opened this issue Dec 11, 2014 · 1 comment

Comments

@levacic
Copy link

levacic commented Dec 11, 2014

var data = [
    {
        "title": "Foo",
        "tags": ["foo", "bar", "baz"]
    },
    {
        "title": "Bar",
        "tags": ["bar", "qux"]
    }
];

It would be great to have the ability to search the data based on the tags property. It's possible to hack this up in user-code by concatenating the tags property into a string, with a unique imploding character, e.g.

var data = [
    {
        "title": "Foo",
        "tags": ["foo", "bar", "baz"],
        "_tags": "foo_bar_baz"
    },
    {
        "title": "Bar",
        "tags": ["bar", "qux"],
        "_tags": "bar_qux"
    }
];

...and search through that transformed data instead, but this is neither a clean nor a stable solution.

@hagabaka
Copy link

Maybe the search/sort "field" options can be generalized to take a function to map each item, for example

search('bar', fields: [
  function(item, term) {
    return item.tags.indexOf(item) >= 0;
  },
  'title'
]);

or

search('bar', fields: [
  function(item) {
    return item.tags.join('_');
  },
  'title'
]);

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

2 participants