A
A
Archakov Dennis2016-02-23 14:40:28
JavaScript
Archakov Dennis, 2016-02-23 14:40:28

How to filter objects with a specific id in AngularJS?

There are two ng-repeat with different arrays.
1. Stores a list of categories.
2. List of goods.
Following the selected value from , products should be filtered by the pid
parameter Each product has a pid . And if I select for example the second row from , then Angular takes from - id which is stored in value="2" .
I could do this with simple js. But, I don’t want to invent all sorts of crutches, since I’m already using angular.

<select ng-module="selectFilter" data-placeholder="Выберите категорию" name="category-change">
  <option ng-repeat="cat in cats" value="{{cat.id}}">{{cat.title}}</option>
</select>

and goods:
<div onclick="Product.ShowOrder({{product.id}});" id="product-{{product.id}}" class="product" ng-repeat="product in products | filter:selectFilter">
            <div class="product-btns">
              <span onclick="Product.Edit({{product.id}});" class="sprite-icon edit"></span>
            </div>
            <div class="product-image">
               <img src="{{product.cloud_url}}">
            </div>
            <div class="product-title">{{product.title}}</div>
          </div>

JSON of goods:
[
  {
    "id": "1",
    "parent_id": "1",
    "title": "Вырезка",
    "description": "",
    "price": "679",
    "count": "0",
    "cloud_id": "tuh43zowt9z4ytn2jvop",
    "cloud_url": "tuh43zowt9z4ytn2jvop.jpg"
  },
  {
    "id": "2",
    "parent_id": "3",
    "title": "Ребра",
    "description": "",
    "price": "456",
    "count": "0",
    "cloud_id": "sample",
    "cloud_url": "sample.jpg"
  },
  {
    "id": "3",
    "parent_id": "4",
    "title": "Грудка",
    "description": "курица",
    "price": "500",
    "count": "500",
    "cloud_id": "ymhgwkj618fuyohblsg0",
    "cloud_url": "ymhgwkj618fuyohblsg0.png"
  }
]

JSON categories:
[
  {
    "id": "6",
    "title": "Говядина"
  },
  {
    "id": "4",
    "title": "Полуфабрикаты"
  },
  {
    "id": "2",
    "title": "Курица"
  },
  {
    "id": "3",
    "title": "Баранина"
  },
  {
    "id": "13",
    "title": "Полезности"
  }
]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2016-03-01
@archakov06

<select ng-model="selectFilter" data-placeholder="Выберите категорию" name="category-change" ng-options="item as item.title for item in items track by item.id"></select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question