下拉过滤器在angularjs中不起作用

时间:2022-06-03 19:03:54

I have created a drop down filter in AngularJs. Please see the link.
http://plnkr.co/edit/c5Hrqfv1eA5qfQpkYR41?p=preview
It is working fine, but I want to replace my current JSON to a new one.

我在AngularJs中创建了一个下拉过滤器。请看链接。 http://plnkr.co/edit/c5Hrqfv1eA5qfQpkYR41?p=preview它工作正常,但我想将当前的JSON替换为新的JSON。

    $scope.data={
      "language": "en",
      "0": {
        "id": "2222",
        "deck": [
          {
            "id": "2421",
            "level": "5",
            "name": "Plaza Deck 5"
          },
          {
            "id": "2433",
            "level": "6",
            "name": "Fiesta Deck 6"
          },
          {
            "id": "2442",
            "level": "7",
            "name": "Promenade Deck 7"
          }
        ]
      }
    }

I want to change with the above JSON. Please help.
Thanks.

我想用上面的JSON改变。请帮忙。谢谢。

1 个解决方案

#1


1  

I don't know why you are switching from simpler array to complex array.

我不知道你为什么要从简单的数组切换到复杂的数组。

But here is your solution

但这是你的解决方案

HTML

 <select ng-model="filterDeck1.deckDetail1" ng-options="deck.name for deck in data1['0'].deck">
 </select>

JavaScript

//filter for new json structure
$scope.customDeck1 = function (data) {
    if (data.id === $scope.filterDeck1.deckDetail1.id) {
      return true;
    } else {
      return false;
    }
  };

You can move above filter code from controller to filter, that would be more convenient way to do it.

您可以将上面的过滤器代码从控制器移到过滤器,这将是更方便的方法。

Here is Working Fiddle Hope this could help you. Thanks.

这是工作小提琴希望这可以帮助你。谢谢。

#1


1  

I don't know why you are switching from simpler array to complex array.

我不知道你为什么要从简单的数组切换到复杂的数组。

But here is your solution

但这是你的解决方案

HTML

 <select ng-model="filterDeck1.deckDetail1" ng-options="deck.name for deck in data1['0'].deck">
 </select>

JavaScript

//filter for new json structure
$scope.customDeck1 = function (data) {
    if (data.id === $scope.filterDeck1.deckDetail1.id) {
      return true;
    } else {
      return false;
    }
  };

You can move above filter code from controller to filter, that would be more convenient way to do it.

您可以将上面的过滤器代码从控制器移到过滤器,这将是更方便的方法。

Here is Working Fiddle Hope this could help you. Thanks.

这是工作小提琴希望这可以帮助你。谢谢。