Answer the question
In order to leave comments, you need to log in
How to generate a selection in json and store data for further use using angular?
We have a select field that has a list of names, and depending on the choice of name, it allows you to select details in a separate select field
<div class="form-group">
<label>Имя</label>
<select ng-model="user.name"
ng-options=" name.name for name in names">
</select>
</div>
<div class="form-group">
<label>Режим</label>
<select ng-model="switches.mode"
ng-options="mode.name as mode.name for mode in user.name.modes">
</select>
</div>
{
"name": "hello",
"modes": [
{
"name": "mode1"
}
]
}
{
"name": "hello",
"mode": "mode1"
}
Answer the question
In order to leave comments, you need to log in
all angular can help you with is angular.forEach and angular.copy. as well as map/reduce.
names.map(function (name) {
// можно и без reduce, просто забрать у первого элемента массива значение,
// это просто как пример
name.mode = name.modes.reduce(function (result, item) { return item.name; });
delete name.modes;
return name;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question