我正在尝试制作一个简单的函数,允许我在特定表中搜索特定项目并使用 YDN-DB 返回所需的结果,到目前为止我有这个:
var simpleSearch = function(table,field,string,limit,callback){
var look = db.from(table).where(field, '=', string).list(limit);
look.done(function(result) {
callback(true,result);
});
look.fail(function() {
callback(false,'');
});
}
//usage
simpleSearch('mytable','fieldname','nice field',1,function(found,result){
if(found){
console.log('item '+result.fieldname+' found'); //on success should output 'item nice field found'
}else{
console.log('nothing found');
}
});
现在的问题是,这段代码根本不起作用。你能帮我或指出我哪里错了吗?
提前致谢。