gpt4 book ai didi

javascript - TypeScript错误无法使用 'in'运算符来搜索typescript和pouchdb的 '_id'

转载 作者:行者123 更新时间:2023-12-03 08:01:35 25 4
gpt4 key购买 nike

我在带有 webstorm 和 systemjs 的 typescript 环境中将 pouchDb 与 Angular2 一起使用。在编辑器中,看来我有足够的配置来获取智能感知并且 pouchDB 确实运行。

我有这个测试代码。

  var mydb = new PouchDB('TestDb');
var myObj = {"_id" : "1", "description":"hello world"} ;
var objAsString = JSON.stringify(myObj) ;
mydb.put(objAsString).then(function (response) {
// handle response
console.log("save to db:" + response) ;
}).catch(function (err) {
console.log(err);
});

我收到以下错误

TypeError: Cannot use 'in' operator to search for '_id' in {"_id":null,"description":"hello world"}
at PouchDB.<anonymous> (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:210:21)
at PouchDB.<anonymous> (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:11043:18)
at PouchDB.<anonymous> (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:5996:21)
at PouchDB.<anonymous> (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:11043:18)
at http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:8252:21
at lib$es6$promise$$internal$$initializePromise (http://localhost:63342/clipsalive/node_modules/angular2/bundles/angular2-polyfills.js:1558:9)
at new lib$es6$promise$promise$$Promise (http://localhost:63342/clipsalive/node_modules/angular2/bundles/angular2-polyfills.js:1849:9)
at PouchDB.<anonymous> (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:8239:19)
at PouchDB.put (http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:11043:18)
at http://localhost:63342/clipsalive/node_modules/pouchdb/dist/pouchdb.js:5991:32

我认为这与模块加载有关,我已经在没有 _id 值的情况下进行了尝试,结果相同。

这是一个模块加载问题吗?我该如何解决它?

最佳答案

put PouchDb 中的方法需要 JSON 对象而不是字符串。

您应该只发送对象而不对其进行字符串化。

var myObj = {"_id" : "1", "description":"hello world"} ;
mydb.put(myObj)

关于javascript - TypeScript错误无法使用 'in'运算符来搜索typescript和pouchdb的 '_id',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34559300/

25 4 0
文章推荐: javascript - 相对于窗口高度操纵 div 高度
文章推荐: angularjs - karma-webpack 没有加载 AngularJS 包
文章推荐: syntax-error - JavaScript - 未捕获的 ReferenceError : KEY is not defined
文章推荐: angularjs - 我怎样才能从 View 中隐藏
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com