I have structured data, with various types of data in it. For the sake of simplicity, let's say I have something like this:
{
person : [
{
name : 'paul',
title : 'prof',
profession : 'teacher',
start: '2010-10-10'
},
{
name : 'joe',
title : 'dr',
profession : 'scientist',
start: '2000-01-01'
}
]
book : [
{
title : 'the cat in the hat'
}
]
}
I would like to have an autocomplete box in javascript that lets me choose the names of these structured elements so the following results would be returned given the letter typed:
't' : {'person.title', 'book.title'}
'p' : {'person', 'person.profession'}
What is important to me is that the person might know the name of any of the variables within the tree. So if they type in the name of the top level variable, I only want to show that one and none of it's sub-elements, but if they type in the name of sub-element, I want the full path to that sub-element displayed. If they type in a top-level variable ("person"), I don't want to display all the sub-elements, only ones that always begin with that same set of letters.
Are there any libraries out there that can currently do this (provide a way of doing auto-complete on structured data) as opposed to normal auto-complete?
Clarification: I guess what I need is the ability to tell the auto-complete library a map of inputs and outputs to work with, such that typing "p" will end up hitting on the inputs "person" and "profession" and thus return "person" and "person.profession", and typing "t" hits on "title" for "person.title" and "title" for "book.title".