如何通过在对象属性比较来找到列表中的一个对象 [英] How to find an object in a list by comparing on object property

查看:90
本文介绍了如何通过在对象属性比较来找到列表中的一个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能扫描对象的数组,以便通过匹配对象属性来查找对象:

  $ scope.items = [
  {ID:1,名称:一},
  {ID:2,名称:两节},
  {ID:3,名称:三化}
];$ scope.item = $ scope.items.find({ID:1}); //伪code


解决方案

我曾经下划线JS

  $ scope.item = _.where($ scope.items,{ID:1});

How could I scan an array of objects in order to find an object by matching the object property:

$scope.items = [
  { id: 1, name: 'one' }, 
  { id: 2, name: 'two' }, 
  { id: 3, name: 'three' }
];

$scope.item = $scope.items.find({ id: 1 }); // pseudo-code

解决方案

I Used Underscore js

$scope.item = _.where($scope.items, { id: 1 });

这篇关于如何通过在对象属性比较来找到列表中的一个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆