gpt4 book ai didi

javascript - Angular js : set option value after filling options in select

转载 作者:行者123 更新时间:2023-11-28 00:13:20 25 4
gpt4 key购买 nike

我有一个网络服务,其结果如下:

{
"selectedStateId": "1",
"selectedCityId": "1",
"selectedAreaId": "1",
"states": [{
"stateId": "1",
"stateName": "Gujarat"
}, {
"stateId": "2",
"stateName": "Rajasthan"
}],
"cities": [{
"cityId": "1",
"stateId": "1",
"cityName": "Ahmedabad"
}, {
"cityId": "2",
"stateId": "1",
"cityName": "Surat"
}],
"areas": [{
"areaId": "1",
"cityId": "1",
"areaName": "thaltej"
}, {
"areaId": "2",
"cityId": "1",
"areaName": "Maninagar"
}, {
"areaId": "3",
"cityId": "1",
"areaName": "Naranpura"
}]
}

现在,我想将州、城市和地区的数组绑定(bind)到三个不同的 select 并使用作为父对象成员的 stateId、cityId 和 areaId 设置其值。

两个问题:

  1. 如何设置三个不同select的值?
  2. 如果我们有对象数组(我在上面创建的数组),我们如何实现 (1)?

谢谢。

编辑:我想前两个答案有一些误解。所以,改变了我的数据表示。我想将 selectedStateId 设置为 states 的 select 元素,将 selectedCityId 设置为 select 元素城市等等..现在,我想你应该清楚我的要求了..

最佳答案

我在这里为你创建了一个plunker。请用具有 3 个选择的 html 来查看它

<select>....</select>

"http://plnkr.co/edit/LaypSCATZyQxLHYHjgnB?p=preview "

关于javascript - Angular js : set option value after filling options in select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682101/

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