1

我有一个工作选择选项,其中包含一些过滤数据以供搜索的值。

现在我需要几个链接作为侧边栏,这有助于直接单击并更改上面的选择选项

请参考我制作的这个链接网站链接


登录示例:

用户:recobee@gmail.com

通行证:基肖尔

http://proconstruct.co.in/jsearch


Javascript:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  var json = {
    "modules":
        <?php echo $qres; ?>
  };

  $scope.ocw = json;

  var allCategories = json.modules.map(function(item) {
    return item.designation
  });
  var filteredCategories = [];

  var allCities = json.modules.map(function(item) {
    return item.city
  });
  var filteredCities = [];


  allCategories.forEach(function(item) {
    if (filteredCategories.indexOf(item) < 0 && item) {
      filteredCategories.push(item);
    }
  });

  allCities.forEach(function(item) {
    if (filteredCities.indexOf(item) < 0 && item) {
      filteredCities.push(item);
    }
  });

  $scope.search = {
    designation: ""
  }
  $scope.search = {
    city: ""
  }

  $scope.categories = filteredCategories;

  $scope.updateFilter = function(value) {
    $scope.search.designation = value;
  }


  $scope.cities = filteredCities;
  $scope.updateFilter = function(value) {
    $scope.search.city = value;
  }

});

这些是链接 html :

<div  ng-repeat="designation in categories ">
    <a ng-click="updateFilter(search.designation)"> {{designation}}</a>
</div>

这是正在工作的选择,必须通过链接做出反应:

<select ng-model="search.designation">
    <option value="">All Categories</option>
    <option ng-repeat="category in categories" value="{{category}}">{{category}}</option>
</select>
4

1 回答 1

2

通过快速查看您的代码,我将尝试更改以下内容:

<div  ng-repeat="designation in categories ">
     <a ng-click="updateFilter(designation)"> {{designation}}</a>
</div>

我唯一改变的是 updateFilter 函数的参数。

[ 更新 ]

您还有两个同名函数:updateFilter

也试试这个:

$scope.search = {
    designation: "",
    city: ""
}

$scope.updateFilterDesignation = function(value) {
    $scope.search.designation = value;
}
$scope.updateFilterCity = function(value) {
    $scope.search.city = value;
}

所以链接应该这样做: ng-click="updateFilterDesignation(designation)"

这应该很有希望。

于 2015-03-24T08:27:33.090 回答