在下面的代码中,我试图在对getCollection函数的调用中调用对象DbModels的函数getCollection:
DbModels.prototype.addUser = function(Users, callback) {
this.getCollection("seq", function(error, seq_collection) {
if( error ) callback(error)
else {
var ID = seq_collection.find({_id: 'Users'}, {'seq': 1});
console.log("ID is: "+ID);
console.log(this.parent);
this.getCollection("Users", function(error, sel_collection) {....
但是,这不起作用,因为这是指第一个getCollection。如何在调用get collection中调用getCollection函数?
我已经尝试过this.parent,但这并不能解决问题。
谢谢!
答案 0 :(得分:0)
事先将其存储到变量中:
DbModels.prototype.addUser = function(Users, callback) {
var self = this;
this.getCollection("seq", function(error, seq_collection) {
if( error ) callback(error)
else {
var ID = seq_collection.find({_id: 'Users'}, {'seq': 1});
console.log("ID is: "+ID);
console.log(this.parent);
self.getCollection("Users", function(error, sel_collection) {....