I am trying to get the list of all values from a nested array for all objects into one list.
I have the following json file structure:
{
"booklist": {
"fiction": [
{
"key": "book1",
"value": "bookvalue1"
},
{
"key": "book2",
"value": "bookvalue2"
}
],
"romance": [
{
"key": "book3",
"value": "bookvalue3"
},
{
"key": "book4",
"value": "bookvalue4"
}
],
"thriller": [
{
"key": "book5",
"value": "bookvalue5"
},
{
"key": "book6",
"value": "bookvalue6"
}
]
}
I am trying (what i have tried) to read the list of all books in my dropdown menu:
<ui-select name="books" ng-model="model.books" theme="selectize" required>
<ui-select-match> {{$select.selected.value}} </ui-select-match>
<ui-select-choices
repeat="r.key as r in booklist | filter: $select.search">
<div ng-bind-html="r.value | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
so that the dropdown menu will look like this:
bookvalue1
bookvalue2
bookvalue3
bookvalue4
bookvalue5
bookvalue6
and in another input element, i want to get the category of the selected book above:
<input type="text" name="category" ng-model="model.category" class="form-control" disabled="disabled" value="??"/>
how to get the value for the category of the selected book above?
The ultimate goal is to pass the category value and the book value into my model separately.
important note:
i am not allowed to change the json structure, it should remain as it is. I just have to change and adapt the code to read the info the right way.