javascript - 使用函数参数声明 req.body.parameter
问题描述
如果我使用不同的参数调用它,我想创建一个函数,它应该使用参数来定义一个 req.body 以便在视图中使用。不好的描述,我会说明我的意思:这个函数
function savePaintingsAll(post, profilpictureEncoded,paintingsname,paintingstype) {
if (profilpictureEncoded == null) return;
const profpic = JSON.parse(profilpictureEncoded);
if (profpic != null && imageMimeTypes.includes(profpic.type)) { // If the file is a json obj & from the type image (jpg, png)
const name = paintingsname;
const type = paintingstype;
post.name = new Buffer.from(profpic.data, 'base64') // Buffer.from(where, how)
post.type = profpic.type
}
}
我希望参数paintingname 和paintingtype 来定义我是否调用savePaintingsAll(post, req.body.paintings3, paintings3, paintingsType3)
,但是如果我这样做了,那么如果我将它们放在if 语句中或之外,则参数不会在函数ether 中使用。问题出在哪里?我用ejs,快递。我需要使用数据在数据库中保存不同的绘画并显示它们:
<img id="painting" class="" style="max-width: 20%; min-width: 300px; height: auto;"src="<%= post.paintingsP %>" />
<img id="painting2" class="" style="max-width: 20%; min-width: 300px; height: auto;"src="<%= post.paintingsP2 %>" />
解决方案
推荐阅读
- akka-stream - 将 `func(in: Source[A]) : Source[B]` 转换为 `Flow[A, B]`
- python - 使用 numpy 创建对角矩阵返回零方阵
- pandas - 从 DataFrame 图中制作 seaborn 热图以了解数据范围
- javascript - 用行尾+双引号javascript替换行尾
- java - 将架构添加到具有特定 ID 的架构注册表
- javascript - React :期望一个赋值或函数调用,而是看到一个表达式
- powershell - PowerShell 中的退出代码
- c++ - 错误:控制到达非空函数的结尾 [-Werror=return-type]
- c# - 为什么输入不遵循模式?
- excel - 如何在范围内找到特定颜色,然后如果单元格为 =“”,则将值设为 0 并在单元格中保持相同的颜色