我有4个下拉框。如何基于另一个下拉列表中的选定值填充其他下拉列表中的值
即城市,剧院,showtime,showdate。
目前我的代码填充vlaues一样,根据选择的城市
它填充戏剧,showdate相似和Showtime值。
我想要做什么是
基于slected城市填充影院
然后在该slected影院baesd在Showtime和showdate相似填充值。
这是怎么实现的?
在HTML
<div class="form-group col-lg-12" ng-class="{ 'has-error' : bookticket.city.$invalid && (bookticket.city.$dirty || submitted)}">
<label>Select City</label>
<select name="city" class="form-control"
ng-model="city"
ng-options="city for city in cityList"
ng-required="true" >
\t \t \t \t \t \t \t
\t \t \t \t \t <option value="">Select </option>
</select>
\t \t \t \t <span class="help-block" ng-show="bookticket.city.$invalid && bookticket.city.$error.required && (bookticket.city.$dirty || submitted)" >City Name is required.</span>
</div>
\t \t
\t \t <div class="form-group col-lg-12" ng-class="{ 'has-error' : bookticket.theater.$invalid && (bookticket.theater.$dirty || submitted)}">
<label>Select Theater </label>
<select name="theater" class="form-control"
ng-model="theater"
ng-options="theater for theater in selectedtheater"
ng-required="true">
\t \t \t \t \t \t <option value="">Select </option>
</select>
\t \t \t \t <span ng-show="bookticket.theater.$invalid && bookticket.theater.$error.required && (bookticket.theater.$dirty || submitted)" class="help-block">Theater Name is required.</span>
</div>
\t \t
<div class="form-group col-lg-6" ng-class="{ 'has-error' : bookticket.showdate.$invalid && (bookticket.showdate.$dirty || submitted)}">
<label>Select Show Date </label>
<select name="showdate" class="form-control"
ng-model="showdate"
ng-options="showdate for showdate in selectedshowdate"
ng-required="true">
\t \t \t \t \t \t <option value="">Select </option> \t
</select>
\t \t \t \t <span ng-show="bookticket.showdate.$invalid && bookticket.showdate.$error.required && (bookticket.showdate.$dirty || submitted)" class="help-block">Show Date is required.</span>
</div>
\t \t
\t \t <div class="form-group col-lg-6" ng-class="{ 'has-error' : bookticket.showtime.$invalid && (bookticket.showtime.$dirty || submitted)}">
<label>Select Show Time </label>
<select name="showtime" class="form-control"
ng-model="showtime"
ng-options="showtime for showtime in selectedshowtime"
ng-required="true">
\t \t \t \t \t <option value="">Select </option> \t \t
</select>
\t \t \t \t <span ng-show="bookticket.showtime.$invalid && bookticket.showtime.$error.required && (bookticket.showtime.$dirty || submitted)" class="help-block">Show Time is required.</span>
</div>
\t \t
\t \t
控制器代码
$scope.cityList = [
'BANGLORE',
'TUMKUR',
\t 'MYSORE'
];
$scope.theaterList = [
{ name:'BANGLORE',values: ['ABC THEATER (BANGLORE,RAJAJINAGAR)','DEF THEATER (BANGLORE,VIJAYNAGAR)'] },
{ name:'TUMKUR', values: ['HOME THEATER (TUMKUR,TUMKUR STREET)'] },
\t { name:'MYSORE', values: ['MYSORE THEATER (MYSORE ROAD, MYSORE)'] }
];
$scope.city = "";
$scope.theater = "";
$scope.selectedtheater =[];
$scope.$watch('city', function(newValue) {
for (var i = 0; i < $scope.theaterList.length; i++){
if ($scope.theaterList[i].name === newValue){
$scope.selectedtheater = $scope.theaterList[i].values;
}
}
});
$scope.showdateList = [
{name:'BANGLORE', values: ['1-MAR-2017','2-MAR-2017','3-MAR-2017'] },
{name:'TUMKUR', values: ['10-APR-2017','11-APR-2017'] },
\t {name:'MYSORE', values: ['13-JUNE-2017','14-JUNE-2017'] }
]; \t \t \t \t
\t \t \t \t \t
$scope.city = "";
$scope.showdate = "";
$scope.selectedshowdate =[];
$scope.$watch('city', function(newValue) {
for (var i = 0; i < $scope.showdateList.length; i++){
if ($scope.showdateList[i].name === newValue){
$scope.selectedshowdate = $scope.showdateList[i].values;
}
}
});
$scope.showtimeList = [
{name:'BANGLORE', values: ['10 AM','11 AM','2 PM'] },
{name:'TUMKUR', values: ['9 AM','10 AM','4 PM'] },
\t {name:'MYSORE', values: ['9 AM','3 PM'] }
];
\t
$scope.city = "";
$scope.showtime = "";
$scope.selectedshowtime =[];
$scope.$watch('city', function(newValue) {
for (var i = 0; i < $scope.showtimeList.length; i++){
if ($scope.showtimeList[i].name === newValue){
$scope.selectedshowtime = $scope.showtimeList[i].values;
}
}
}); \t
查看可以在选定元素上使用的ng-change。 ng-change =“updateNextSelect()”为例。 Ng-change在选择时触发。所以基本上,您可以创建一个函数,根据您创建的函数中的第一个选择填充下一个选择。 –
你能举出例子代码吗? –