如何在javascript中同步运行数据库查询

时间:2018-05-11 19:07:57

标签: javascript jquery

let positionSettings = require('setting');

function getSetting(element) {
    let setting;
    positionSettings.find({element: element}, function (err,docs) {
        console.log(docs[0].current); // output the value
        setting = docs[0].current;
    });
    return setting;
}

$(document).on("click", "#save" , function(e) {
    console.log(getSetting("abc")); // Output undefined
});

为什么getSetting()函数返回undefined。我怎样才能实现它。

0 个答案:

没有答案