0

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.

    $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.

6
  • How do we suggest without getting your question..please add more explaination Commented Feb 12, 2015 at 6:43
  • @ pankajparkar, I have added working example in plunker. I need the same result with new JSON. Commented Feb 12, 2015 at 6:50
  • "It is working fine, but I want to replace my current JSON to a new one. " what does it mean? why you want to create a new JSON? Commented Feb 12, 2015 at 6:52
  • JSON structure has changed. So filter is not working. Commented Feb 12, 2015 at 9:34
  • Okay now i got that.i'll look at it afterwards..because plnkr.co is down here Commented Feb 12, 2015 at 9:43

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.