【发布时间】:2016-04-06 04:27:18
【问题描述】:
我在带有 webstorm 和 systemjs 的打字稿环境中使用 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 的值,结果相同。
这是一个模块加载问题,我该如何解决?
【问题讨论】:
标签: javascript typescript couchdb pouchdb