【发布时间】:2016-02-04 00:22:58
【问题描述】:
我有一个简单的对象,我在其中传递一个参数,然后我想在我的集合中找到所有文档并标记它。这是我的自定义对象:
var db = require('../lib/db');
function Widget(n,l,c,o,t,p) {
this.name = n;
this.label = l;
this.class = c;
this.order = o;
this.template = t;
this.params = p;
if(this.params != null) {
var a = getValue(this.params);
a.next();
}
}
function *getValue(p){
var Object = require("./sections");
console.log("1");
try {
var objects = yield Object.find({}).exec();
}
catch(err){
throw err;
}
console.log("2");
console.log("obj:" + objects);
}
module.exports = Widget;
这是sections.js
var db = require('../lib/db');
var schema = new db.Schema(
{
title: String,
parent: { type: db.Schema.ObjectId, ref: 'sections' },
child: [{ type: db.Schema.ObjectId, ref: 'sections' }],
updated_on: Date,
created_on: Date
});
module.exports = db.model( 'sections', schema );
我是这样创建对象的:
var widget = new Widget("text","Titiolo",0,0,"text.html","sections");
在我的控制台上我只看到“1”而不是 2 或“objects:”为什么?
【问题讨论】:
标签: javascript node.js koa