1

I could display the result of my pagination query (FaunaDB,FQL) in the console and it appears as a javascript object. Yet, I cannot access the properties of said object and even less can I convert it to an array using the spread operator. How could I do that?

I am aware there exists a pagination helper but could not make it work, as explained above. Here is the latest code I am trying:

var array=[]
qu(q.Map(
    q.Paginate(q.Match(q.Index('FeesByIndex'))),
    q.Lambda(x => q.Get(x))
   )).then(res => { console.log(res); array=[...res] })//the log really looks like a js object and res is said to be one
  

It says type object is not an array type. Also, property data is said not to exist on res, although it clearly does in the console

4

2 回答 2

1

您错过了指定索引词并且 Lambda 存在语法错误。

响应对象有一个数据属性,它是一个列表。

在我的存储库中,如果查询返回多个对象,我将使用此代码段:

    const result: Fee[] = [];

    await CLIENT.query(
      q.Map(
        q.Paginate(
          q.Match(
            q.Index('FeesByIndex'),
            'index term',
          ),
        ),
        q.Lambda('fees', q.Get(q.Var('fees'))),
      )
    )
    .then(faunaResponse => {
      const dataArray = faunaResponse.data;
      dataArray.forEach(s => {
        const data = s.data;
        result.push({
          id: data.id,
          yourProp1: data.yourProp1,
          yourProp2: data.yourProp2,
        });
      });
    })
    .catch(e => logger.error(e));
于 2021-01-15T06:23:27.280 回答
0

你会尝试这种方式吗?

var array=[]
  qu(q.Select(['data'],
      q.Map(
          q.Paginate(q.Match(q.Index('FeesByIndex'))),
          q.Lambda(x => q.Get(x))
      )
    )
  ).then(res => { console.log(res); array=[...res] })
于 2020-09-17T12:15:55.313 回答