本文介绍了等效于jQuery中的Underscore.js _.pluck的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道与下划线数组方法匹配的'pluck'插件吗?

Does anyone know of a 'pluck' plugin that matches the underscore array method?

pluck_.pluck(list, propertyName)

地图的最常见用例的便捷版本:提取属性值列表.

A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.

var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
_.pluck(stooges, 'name');
=> ["moe", "larry", "curly"]

Google今天对我没有太大帮助.任何表示赞赏的指针

Google is not helping me much today.Any pointers much appreciated

推荐答案

您可以使用表达式来实现;

You can do it with an expression;

var arr = $.map(stooges, function(o) { return o["name"]; })

这篇关于等效于jQuery中的Underscore.js _.pluck的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 09:43