所以我有点卡在与前一个选择模型相连的3rc select
上。
首先,您必须选择分支,之后您可以选择建筑物名称以及楼层。
vm.locations数据
[
{
"_id": "5a61acfdd5df1761dd2eb1ef",
"branch": "Lucena City",
"__v": 0,
"building": [
{
"name": "mhq",
"floors": [
"1st",
"2nd",
"3rd"
]
}
],
"dateCreated": "2018-01-19T08:31:57.121Z"
},
{
"_id": "5a61ad6fd5df1761dd2eb1f1",
"branch": "Lucban",
"__v": 0,
"building": [
{
"name": "mhq",
"floors": [
"ground floor",
"2nd floor",
"3rd floor",
"4th floor",
"5th floor"
]
}
],
"dateCreated": "2018-01-19T08:33:51.761Z"
},
{
"_id": "5a61ada1d5df1761dd2eb1f2",
"branch": "loperz",
"__v": 0,
"building": [
{
"name": "lope",
"floors": [
"ground floor",
"1st floor"
]
}
],
"dateCreated": "2018-01-19T08:34:41.904Z"
}]
html side
<div class="row justify-content-md-center">
<div class="col-md-4">
<label for="branch">
<strong>Branch</strong>
</label>
<select ng-options="loc as loc.branch for loc in vm.locations" ng-model="vm.locationTest" class="form-control">
</select>
<small id="emailHelp" class="form-text text-muted">Select branch.</small>
</div>
<div class="col-md-4">
<label for="building">
<strong>Building</strong>
</label>
<select ng-options="ds as ds.building for ds in vm.locationTest" ng-model="vm.roomData.building" class="form-control">
</select>
</div>
<div class="col-md-4">
<label for="roomFloor">
<strong>Room Floor</strong>
</label>
<select ng-options="ds as ds for ds in vm.locationTest.floors" ng-model="vm.roomData.roomFloor" class="form-control">
</select>
</div>
选择分支是有效的,之后我无法将数据传递给第2和第3 select
。我不擅长处理对象数据。
答案 0 :(得分:1)
看起来你有一个错字:
<select ng-options="ds as ds.building for ds in vm.locationTest" ng-model="vm.roomData.building" class="form-control">
</select>
具体而言,vm.locationTest
应为vm.locationTest.building
而ds.building
应为ds.name
那么它将是:
<select ng-options="ds as ds.name for ds in vm.locationTest.building" ng-model="vm.roomData.building" class="form-control">
</select>
然后,我们还需要修复第3个ng-options
:
vm.locationTest.floors
变为vm.roomData.building.floors