javascript - Find items in inner array - angularJS -


i have function in angularjs uses find check if item exists in array;

function matchcartitem(item) {     return $scope.cart[0].cart_items.find(function(itm) {         return itm.item_id === item.item_id     }); } 

as can see pass item function check if item_id of passed item can found in items in cart_items array

this works great want modify it.

cart_items has inner array cart_modifier_items . when cart_item passed contains cart_modifier_items. function @ moment checks matching cart_item

how can change function check cart_modifier_items?

so want check matching item.item_id in $scope.cart[0].cart_items -- function this

but check matching item.cart_modifier_item[i] in$scope.cart[0].cart_items[i].cart_modifier_itemswhereiis looping through thecart_items`

any help/guidance appreciated

data structure of item

cart_item: [     {       "id": 159,       "item_id": 20,       "name": "empanadas (choice of 2)",       "description": "choice of diced beef; spinach, stilton , onion; or smoked ham , mozzarella",       "price": 700,       "available": 1,       "created_at": "2016-01-31 16:50:31",       "updated_at": "2016-01-31 16:50:31",       "menu_category_id": 41,       "restaurant_id": 11,       "cart_modifier_items": [           {               "id": 34,               "item_id": 29,               "name": "diced beef",               "price": 0,               "created_at": "2016-02-01 01:04:08",               "updated_at": "2016-02-01 01:04:08",               "menu_modifier_group_id": 9,               "restaurant_id": 11,               "menu_item_id": 159           },           {               "id": 35,               "item_id": 10,               "name": "smoked salmon & mozzarella",               "price": 0,               "created_at": "2016-02-01 01:04:37",               "updated_at": "2016-02-01 01:04:37",               "menu_modifier_group_id": 9,               "restaurant_id": 11,               "menu_item_id": 159           }         ]     } ] 

use standard some instead of find:

function matchcartitem(item) {     return $scope.cart[0].cart_items.some(function(itm) {         return itm.item_id === item.item_id;     }); } 

some checks if item in array satisfies condition.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -