Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS应用程序中u.find Lodash语句中的花括号_Javascript_Angularjs_Lodash - Fatal编程技术网

Javascript AngularJS应用程序中u.find Lodash语句中的花括号

Javascript AngularJS应用程序中u.find Lodash语句中的花括号,javascript,angularjs,lodash,Javascript,Angularjs,Lodash,在我的新工作中,我继承了一个非常混乱的AngularJS项目。我最近一直在尝试解决一个bug,该bug包含以下Lodash语句: var group = _.find(groupList, {id: id}); 从上的可用文档中,我可以找到与3.7.0版本最接近的一个版本,uz.find函数迭代集合并返回语句所针对的第一个对象。表达式中的第二项表示要执行的函数 然而,我对{id:id}在这个实例中的作用感到困惑。这是一个有角度的表达吗?它到底在这里干什么?任何帮助都将不胜感激。这意味着-在数

在我的新工作中,我继承了一个非常混乱的AngularJS项目。我最近一直在尝试解决一个bug,该bug包含以下Lodash语句:

 var group = _.find(groupList, {id: id});
从上的可用文档中,我可以找到与3.7.0版本最接近的一个版本,uz.find函数迭代集合并返回语句所针对的第一个对象。表达式中的第二项表示要执行的函数


然而,我对{id:id}在这个实例中的作用感到困惑。这是一个有角度的表达吗?它到底在这里干什么?任何帮助都将不胜感激。

这意味着-在数组中搜索一个对象,该对象具有属性id和变量id的值

var-groupList=[{id:21,名称:'cats'},{id:17,名称:'dogs'},{id:701,名称:'rats'}]; var-id=17; var group=..findgroupList,{id:id}; console.loggroup;
也许可以尝试阅读你发布的链接中的所有文档?具体来看以下示例:

var users = [
  { 'user': 'barney',  'age': 36, 'active': true },
  { 'user': 'fred',    'age': 40, 'active': false },
  { 'user': 'pebbles', 'age': 1,  'active': true }
];

_.result(_.find(users, function(chr) {
  return chr.age < 40;
}), 'user');
// => 'barney'

// using the `_.matches` callback shorthand
_.result(_.find(users, { 'age': 1, 'active': true }), 'user');
// => 'pebbles'

// using the `_.matchesProperty` callback shorthand
_.result(_.find(users, 'active', false), 'user');
// => 'fred'

// using the `_.property` callback shorthand
_.result(_.find(users, 'active'), 'user');
// => 'barney'
我相信第二个例子说

//使用u.matches回调速记


回答您的问题。

搜索属性id与id变量相同的对象。表达式中的第一个id是属性还是变量?第一个id是变量还是属性?不,它是对象,例如{id:null},变量id是第二个{id:id}。