- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个 Node js 应用程序,其中一个页面是 DHTMLX 调度程序。但是,无论何时加载页面,应用程序都会崩溃,并且出现以下错误:
TypeError:无法读取 EventEmitter 处未定义的属性“应用”。(/node_modules/mongoskin/lib/collection.js:52:21))
这是错误引用的模块:
SkinCollection.prototype._open = function(callback) {
var collection_args = this._collection_args.concat([callback]);
this._skin_db.open(function(err, db) {
if(err) return callback(err);
db.collection.apply(db, collection_args);
});
}
这是我的 app.js 中导致错误的部分,当我不包含此代码时,日历不会使应用程序崩溃,但我无法将数据发送到我的 MongoDB atlas 集群。
应用程序.js
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/init', function(req, res){
db.event.insert({
text:"My test event A",
start_date: new Date(2018,8,1),
end_date: new Date(2018,8,5)
});
db.event.insert({
text:"My test event B",
start_date: new Date(2018,8,19),
end_date: new Date(2018,8,24)
});
db.event.insert({
text:"Morning event",
start_date: new Date(2018,8,4,4,0),
end_date: new Date(2018,8,4,14,0)
});
db.event.insert({
text:"One more test event",
start_date: new Date(2018,8,3),
end_date: new Date(2018,8,8),
color: "#DD8616"
});
res.send("Test events were added to the database")
});
app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
//set id property for all records
console.log(err);
for (var i = 0; i < data.length; i++)
data[i].id = data[i]._id;
//output response
res.send(data);
});
});
app.post('/data', function(req, res){
var data = req.body;
var mode = data["!nativeeditor_status"];
var sid = data.id;
var tid = sid;
delete data.id;
delete data.gr_id;
delete data["!nativeeditor_status"];
function update_response(err, result){
if (err)
mode = "error";
else if (mode == "inserted")
tid = data._id;
res.setHeader("Content-Type","application/json");
res.send({action: mode, sid: sid, tid: tid});
}
if (mode == "updated")
db.event.updateById( sid, data, update_response);
else if (mode == "inserted")
db.event.insert(data, update_response);
else if (mode == "deleted")
db.event.removeById( sid, update_response);
else
res.send("Not supported operation");
});
过去一周我才开始学习 javascript,对编码还很陌生。我不明白为什么会出现此错误。当我将 Scheduler 应用程序作为独立功能运行时,它可以完美运行。只有当我尝试在我的网站中实现它时,它才会抛出此错误。
最佳答案
更新:正确答案
此问题与以下问题重复:MongoSkin "Cannot read property 'apply' of undefined"
Mongoskin只支持MongoDB 2.x,使用MondoDB 3.x时会出现这个错误。
原始(不正确)答案
我自己是 MongoDB 的新手,但我很确定问题在于您需要将 collection
替换为该行中表的实际名称:
db.collection.apply(db, collection_args);
例如,如果表/集合的名称是 skin
,则该行将变为:
db.skin.apply(db, collection_args);
(注意当 app.j
对事件表执行数据库操作时,它是如何调用 db.event.insert()
等...)
关于javascript - 类型错误 : Cannot read property 'apply' of undefined at EventEmitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54506180/
我已经尝试了很长时间自己解决这个问题,但找不到适合我的问题的解决方案。 我有这个方法: handle_database = function(callback, req, res) { pool.ge
我差点把问题标题写成 - Communicating between eventEmitters 我有一个全局范围内的 node.js 模块 (X)(它使用 eventEmitter)。然后我有每个套
我正在尝试从一个 EventEmitter 发射到另一个 EventEmitter,或者寻找替代解决方案。下面的代码不起作用。 多发射器示例 var events = require('events'
有很多示例在自定义事件发射器构造函数中未使用 events.EventEmitter.call(this),而其他示例正在使用它 (official documentation): var event
假设我有这段代码: export class ProductsListComponent { @Output() onProductSelected: EventEmitter; constr
有时我们会遇到泛型变量应该被省略的情况。像这样: @Component( ... ) class MyComponent { @Output() public cancel = new Eve
我想做这样的事情: var events = require("events"); var emitterA = new events.EventEmitter(); var emitterB = n
EventEmitter.emit() 和 EventEmitter.next() 有什么区别?两者都将事件分派(dispatch)给订阅的监听器。 export class MyService {
我是 angular2 的新手,我对使用 EmitterService 的 EventEmitter 感到困惑,任何人都可以向我解释 Emitter 的用途。 在不使用@input 和@output
我正在学习 Node.js,对自定义 EventEmitter 有一些困惑。代码如下: var events = require("events"); function MyEmitter (name
如标题所述,我想用 TypeScript 重写下面的语句 EventEmitter = require('events').EventEmitter ES6风格 import {EventEmitte
obj.prototype.__proto__ = events.EventEmitter.prototype 我有时会看到上面的代码,我用谷歌搜索了一下,他们说这一行将所有 EventEmitter
我创建了一个抽象父类(super class)来处理我应用中各种表单组件的通用因素。 出于某种原因,我无法正确捕获由在父类(super class)中声明了 EventEmitter 的派生类发出的事
我尝试将表单从我的子组件传递给他的父组件。 child TS: @Output() submit: EventEmitter = new EventEmitter(); updateStream():
这真的很奇怪,也很难解释。 我用过EventEmitter在我的一些服务中,我一直在使用它来更改我的 View 数据。 我遇到了更改路线(通过链接或通过历史返回)的问题,它似乎被多次触发,因此它搞乱了
我正在开发一个 Angular2 组件,它使用网络摄像头将图片捕捉到 Canvas 元素,并将其提取为 Blob。 Blob 和事件分别正常工作,但是当我尝试从 toBlob 的回调函数内发出事件时,
当我有一个带有选择器'recursive-element'的模板时,它的模板看起来像这样 在我定义的类中 greetEvent = new EventEmitter
我非常喜欢将函数导出为 JavaScript 模块的主要 API 的模式。原因是在 JS 中,函数基本上可以做典型对象可以做的任何事情,然后再做一些。 所以这对我来说很典型: function stu
我有这个 Node js脚本: var EventEmitter = require('events').EventEmitter, util = require('util'); var p
在事件生成后附加事件处理程序有一个看似众所周知的问题。这主要是在调用遵循返回 EventEmitter 模式的函数时出现的问题,例如: var EventEmitter = require('even
我是一名优秀的程序员,十分优秀!