Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs ng重复可靠选择框_Javascript_Angularjs_Combobox_Ng Options - Fatal编程技术网

Javascript angularjs ng重复可靠选择框

Javascript angularjs ng重复可靠选择框,javascript,angularjs,combobox,ng-options,Javascript,Angularjs,Combobox,Ng Options,我想让我的选择框可靠,因此,如果我选择“美国”地区,第二个选择框应该只显示纽约,但我不知道如何制作,我尝试在我的选项中使用ng click,但它不起作用。我不能更改我的数据库类型,我需要使用它,所以有人知道如何在不更改任何数据库结构的情况下创建它吗 var-app=angular.module('app',[]); 应用程序控制器('ctrl',函数($scope){ $scope.countryList=[]; $scope.data=[ {id:1,国家代码:“KR”,国家名称:“韩国”,

我想让我的选择框可靠,因此,如果我选择“美国”地区,第二个选择框应该只显示纽约,但我不知道如何制作,我尝试在我的选项中使用ng click,但它不起作用。我不能更改我的数据库类型,我需要使用它,所以有人知道如何在不更改任何数据库结构的情况下创建它吗

var-app=angular.module('app',[]);
应用程序控制器('ctrl',函数($scope){
$scope.countryList=[];
$scope.data=[
{id:1,国家代码:“KR”,国家名称:“韩国”,城市名称:“釜山”,城市代码:“PUS”},
{id:1,国家代码:“KR”,国家名称:“韩国”,城市名称:“首尔”,城市代码:“SEL”},
{id:1,国家代码:“KR”,国家名称:“韩国”,城市名称:“蔚山”,城市代码:“USN”},
{id:1,国家代码:“KR”,国家名称:“韩国”,城市名称:“光州”,城市代码:“KWJ”},
{id:1,国家代码:“KR”,国家名称:“Korea”,城市名称:“Gunsan”,城市代码:“KUV”},
{id:1,国家代码:“美国”,国家名称:“美国”,城市名称:“纽约”,城市代码:“纽约”}
];
对于(变量i=0;i<$scope.data.length;i++){
var isExist=false;
对于(变量j=0;j<$scope.countryList.length;j++){
if(JSON.stringify($scope.data[i].country\u code)==JSON.stringify($scope.countryList[j].country\u code)){
isExist=真;
打破
}
}
if(isExist==false){
$scope.countryList.push($scope.data[i]);
}
}
});

区域
{{country.country{u name}
详细资料
{{城市.城市名称}

您可以根据选择的第一个下拉列表的
国家/地区代码
对第二个下拉列表应用过滤器。我还替换了下拉列表以使用
ng选项
。还应该考虑将<代码> ng模型< /代码>添加到每个选择框。

<select class="small_select" ng-model="selectedRegion" 
  ng-options="country.country_name as country_code for in countryList">
  <option disabled selected hidden>Region</option>
</select>

<select class="big_select" ng-model="selectedCity"
 ng-options="city.city_code as city.city_name for city in data | filter: {country_code: selectedRegion }">
  <option disabled selected hidden>Detailed information</option>
</select>

区域
详细资料

您可以根据选择的第一个下拉列表的
国家/地区代码
对第二个下拉列表应用过滤器。我还替换了下拉列表以使用
ng选项
。还应该考虑将<代码> ng模型< /代码>添加到每个选择框。

<select class="small_select" ng-model="selectedRegion" 
  ng-options="country.country_name as country_code for in countryList">
  <option disabled selected hidden>Region</option>
</select>

<select class="big_select" ng-model="selectedCity"
 ng-options="city.city_code as city.city_name for city in data | filter: {country_code: selectedRegion }">
  <option disabled selected hidden>Detailed information</option>
</select>

区域
详细资料

如何在不使用ng选项的情况下制作?可能吗?啊,我知道了,但问题是,这个“区域”不再显示了,为什么以及如何显示?谢谢如何在不使用ng选项的情况下制作?可能吗?啊,我知道了,但问题是,这个“区域”不再显示了,为什么以及如何显示?谢谢