У меня есть три объекта: Project
, Customer
и Reference
A Project
имеет два поля выбора: Customer
и Reference
.
В объекте Customer
есть несколько References
.
Поэтому Reference
доступен для выбора, только если выбран Customer
с References
.
Моя проблема : у меня либо работает Reference
, либо начальная загрузка Customer
, но не оба.
При загрузке Project
с этим Customer
правильно отображается в поле выбора:
<select id="customer" ng-model="selectedProject.customer"
ng-options="customer.id as customer.name for customer in customers | orderBy:'name'">
<option value="">keine Angabe</option>
</select>
Но References
не показывается, хотя для выбранного Customer
есть некоторые.
<select id="reference" ng-model="selectedProject.reference"
ng-options="reference.name for reference in selectedProject.customer.references track by reference.id">
<option value="">keine Angabe</option>
</select>
Если я изменю выбор Customer
на этот, отображаются References
, но поле выбора Customer
пусто при загрузке Project
:
<select id="customer" ng-model="selectedProject.customer"
ng-options="customer.name for customer in customers | orderBy:'name' track by customer.id">
<option value="">keine Angabe</option>
</select>Project
Как мне заставить работать оба?
EDIT
Я получил обе работы, выполнив это:
ng-options="customer as customer.name for customer in customers | orderBy:'name'"
И перезаписать идентификатор объекта на Project
выделение:
$scope.selectedProject.customer = $scope.getCustomer($scope.selectedProject.customer);
Но теперь возникает новая проблема, я больше не могу сохранить проект, так как он ожидает ссылку, а не объект заказчика.