有人可以帮我解决我的错误吗,我的代码是:
const { UserLogs } = require("../models");
let logscontroller = {};
logscontroller.getAll = (req, res) => {
console.log(req.body);
let search = req.body.search.value;
console.log(search);
if (search === "") {
UserLogs.findAll({
offset: req.body.start,
limit: req.body.length,
order: [["id", "ASC"]],
raw: true
})
.then(result => {
res.json({
data: result
});
})
.catch(err => {
console.log(err);
});
} else {
UserLogs.findAll({
where: {
email: {
$or: search
}
},
offset: req.body.start,
limit: req.body.length,
order: [["id", "ASC"]],
raw: true
})
.then(result => {
res.json({
data: result
});
})
.catch(err => {
console.log(err);
});
}
return;
};
logscontroller.index = (req, res) => {
res.render("logs", {
title: "Logs Users"
});
};
module.exports = logscontroller;
还有我的错误,我不知道为什么......
TypeError:value.map不是函数 at Object._whereBind(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:2180:21) at Object.whereItemQuery(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:2070:19) 在Utils.getComplexKeys.forEach.prop(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:1957:25) 在Array.forEach() at Object.whereItemsQuery(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:1955:35) at Object.getWhereConditions(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:2423:19) 在Object.selectQuery(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ dialects \ abstract \ query-generator.js:1133:28) 在QueryInterface.select(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ query-interface.js:1077:27) 在Promise.try.then.then.then(D:\ HASH \ back-office-2 \ node_modules \ sequelize \ lib \ model.js:1596:34) 在tryCatcher(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ util.js:16:23) 在Promise._settlePromiseFromHandler(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ promise.js:512:31) 在Promise._settlePromise(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ promise.js:569:18) 在Promise._settlePromise0(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ promise.js:614:10) 在Promise._settlePromises(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ promise.js:693:18) at Async._drainQueue(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ async.js:133:16) at Async._drainQueues(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ async.js:143:10) 在Immediate.Async.drainQueues(D:\ HASH \ back-office-2 \ node_modules \ bluebird \ js \ release \ async.js:17:14) 在runCallback(timers.js:789:20) 在tryOnImmediate(timers.js:751:5) at processImmediate [as _immediateCallback](timers.js:722:5)
答案 0 :(得分:0)
根据 Sequelize Doc ,$or
接受数组:
$or : [{authorId: 12}, {authorId: 13}]
这就是你用过的东西
email: {
$or: search
}
我认为你需要的是:
email : search // for exact match
or
email : {
$ilke : `%${search}%` // for partial match
}