gpt4 book ai didi

javascript - 使用 ng-model 和 ng-options 进行 Angular JS 级联选择

转载 作者:行者123 更新时间:2023-12-03 02:39:16 26 4
gpt4 key购买 nike

所以我有点卡在连接到先前选择模型的 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 端

<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>

选择一个分支有效,之后我无法将数据传递到第二个和第三个select。我不太擅长处理对象数据。

最佳答案

看起来您这里有一个拼写错误:

<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.buildingds.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>

然后,我们还需要修复第三个 ng-options:

vm.locationTest.floors 变为 vm.roomData.building.floors

关于javascript - 使用 ng-model 和 ng-options 进行 Angular JS 级联选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48396760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com