0
나는 자기 정의 개체의 nedb 모듈 캡슐화 :
nedb : find() 함수에서 문서를 가져 오는 방법은 무엇입니까?
var Record = function() {
var Datastore = require('nedb');
this.db = new Datastore({filename: 'record'});
this.db.loadDatabase();
};
을 그리고 데이터베이스의 모든 개체를 얻기 위해 내 자신의 함수를 정의 할 :
Record.prototype.getItems = function() {
var items = null;
this.db.find({}, function(err, docs) {
items = docs;
});
return items;
};
그러나 변수 "items"는 변수 "docs"에 할당 될 수 없으며 항상 "null"입니다. JavaScript의 비동기 특성 때문에 발생한다는 사실을 알고 있습니다.
하지만 어떻게 "docs"변수를 가져올 수 있습니까?