[英]Lazy.js how to select distinct (uniq) by two fields
We are using Lazy.js. 我们正在使用Lazy.js。
If I have selected one field, I know I can use the uniq(fieldName)
function to get distinct results. 如果选择了一个字段,则知道可以使用
uniq(fieldName)
函数获得不同的结果。
For example: 例如:
var uniqueValues = Lazy(someArray)
.map(function (e) { return e.fieldName })
.uniq()
.value();
How do you do the same operation on two fields? 您如何在两个字段上执行相同的操作?
This is what I tried: 这是我尝试的:
var uniqueValues = Lazy(someArray)
.map(function (e) return { FieldName1 : e.fieldName1, FieldName2 : e.fieldName2 })
.uniq();
.value();
But it's not making it distinct by both fields. 但这并不能使这两个领域都与众不同。
uniq
can take in a function parameter which can return which specific field to run the distinct by. uniq
可以接受一个函数参数,该参数可以返回运行特定字段的特定字段。
For example: 例如:
var uniqueValues = Lazy(someArray)
.map(function (e) return { FieldName1 : e.fieldName1, FieldName2 : e.fieldName2 })
.uniq(function (e) { return e.FieldName1 })
.value();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.