【问题标题】:how to manipulate data retrieved from pouchdb如何操作从 pouchdb 检索到的数据
【发布时间】:2017-08-26 10:52:35
【问题描述】:

您好,我正在尝试学习 pouchDB,但遇到了无法操作数据的问题。

db.allDocs({

    include_docs: true
}).then(function(res){
    var r = res.filter(function(){

         });
});

我收到以下错误:

       Uncaught (in promise) TypeError: res.filter is not a function(…)

我尝试在结果集上运行的任何数组函数都出现此错误。 请建议如何正确使用 pouchDB 来过滤结果并从中获取所需的文档。

【问题讨论】:

  • res 的类型是什么?是数组吗?
  • 它是一个对象,但是一个对象可以与数组函数一起使用,对吗?当我 console.log(res) 它列出了所有对象,但如果我 console.log(res[0]) 它说 undefined

标签: javascript node.js hybrid-mobile-app pouchdb nosql


【解决方案1】:

数组函数不能与对象一起使用。

您可以将res 转换为数组,然后您可以使用filter 函数

db.allDocs({

    include_docs: true
}).then(function(res){
    var r = [res].filter(function(){

         });
});

它应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 2021-09-07
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多