AngularJS - 将选择列表值传递给函数返回undefined

时间:2015-11-23 16:46:13

标签: angularjs angularjs-scope

我有3个选择列表,我试图将所选值传递给函数。



		$scope.mapSelections = function(location) {

		  var filteredPins = [];

		  console.log('location:' + location);
          
            var region = (location ? location.location.Region : '');
		    var state = (location ? location.state.StateName : '');
		    var city = (location ? location.city.CityName : '');

		  $scope.dataObject.forEach(function(itemElement, itemIndex) {
		    itemElement.Locations.forEach(function(locationElement, locationIndex) {
		      if (locationElement.Region === region || !region) {
		        locationElement.Sites.forEach(function(siteElement, siteIndex) {
		          if ((siteElement.State == state && !city) || siteElement.City == city || (!state && !city)) {
		            filteredPins.push(siteElement);
		            // console.table(filteredPins)
		            return false;
		          }
		        });
		      }
		    });
		  });

		  $scope.filteredPins = filteredPins;
		  $scope.zoomToIncludeMarkers();

		};

<column>
  <select name="selectRegion" class="form-control" ng-model="selectRegion" ng-change="regionSelected(); mapSelections(location.Region)" ng-options="location as location.Region for location in locationObject | orderBy: location.Region:reverse track by location.Region">
    <option value="">Select Region</option>
  </select>

  <select name="selectState" class="form-control" ng-disabled="!selectRegion" ng-model="selectState" ng-change="mapSelections(state.StateName)" ng-options="state as state.StateName for state in selectRegion.States | unique: 'state.StateName' | orderBy: 'StateName' ">
    <option value="">{{regionSelectMsg}}</option>
  </select>

  <select name="selectCity" class="form-control" ng-disabled="!selectState" ng-model="selectCity" ng-change="mapSelections(city.CityName)" ng-options="city as city.CityName for city in selectState.Cities | unique: 'city.CityName' | orderBy: 'CitytName' ">
    <option value="">Select City</option>
  </select>
</column>
&#13;
&#13;
&#13;

我想将选择列表选择的值传递给ng-change中的mapSelections函数,此时它将在嵌套的forEach循环中用于从模型中获取值并将其推送到新数组

尝试将每个选择列表的ng模型传递给该函数会导致该值未定义。我还尝试在ng-repeat(location.Region,state.StateName和city.CityName)中使用迭代器但没有成功。

见Plunkr:http://plnkr.co/edit/qaLFYD?p=preview

0 个答案:

没有答案