0

您好,我需要以某种方式传递过滤器方法 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")))}
    )}
  })
4

1 回答 1

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")))
        })
    }
})

所以没有经过测试,但我认为应该可以。当您嵌套两个函数时,外部函数的参数在内部函数中可用。

于 2018-04-23T09:19:52.227 回答