你好我需要以某种方式传递过滤器方法2个或多个参数。
像r.table("N/A").filter(function(arg1,arg2){..code here})
我需要以下内容:
我有如下数据结构:
"client":{
"name":"andrew",
"coords":{"lat":200,"long":300}
}
我想获得所有客户端的列表,对于此列表中的每个客户端,我希望他的属性合并与尊重过滤谓词的其他客户端。我需要传递多个参数来过滤功能
clients{
client:{
"name":"andrew",
"coords":{"lat":200,"long":300}
"neighbours":{
"name":"Dean","coords":{"lat":100,"long":200}
"name":"Sean","coords":{"lat":55,"long":120}
}
client:{
"name":"Dean",
"coords":{"lat":100,"long":200}
"neighbours":{
"name":"Sean","coords":{"lat":55,"long":120}
}
client:{
"name":"Sean",
"coords":{"lat":100,"long":200}
"neighbours":{}
}
}
我失败的尝试:
r.db("cldb").table("clt").pluck(
{"name","coord"}).merge(function(currentClient){
return {
r.db("cldb").table("clt").filter(
function(currentClient,neighbourClient){
currentClient("lat").gt(neighbourClient("lat"))
.and(currentClient("long").gt(neighbourClient("long")))}
)}
})
答案 0 :(得分:0)
我不太确定我是否理解你的问题。
r.db("cldb")
.table("clt")
.pluck(["name", "coord"]) // <- [] instead of {}
.merge(function (currentClient) {
return {
// When using objects, you have to specify a property name.
propertyNameThatYouWant: r.db("cldb")
.table("clt")
.filter(function (neighbourClient) {
currentClient("lat")
.gt(neighbourClient("lat"))
.and(currentClient("long").gt(neighbourClient("long")))
})
}
})
所以未经测试,但我认为这应该有效。嵌套两个函数时,外部函数的参数在内部函数中可用。