如何将列表字符串转换为列表布尔值?
List<String> listString = ["true", "false, "true"]
List<bool> listBool = []
我试过了
listBool = listString.map((f)=>(f.contains("true")? listBool.add(true): listBool.add(false)));
我的预期结果是
listBool = [true, false, true]
答案 0 :(得分:0)
您可以尝试使用 forEach 方法,如下所示:
List<String> listString = ["true", "false", "true"];
List<bool> listBool = <bool>[];
listString.forEach((item) => item == "true" ? listBool.add(true) : listBool.add(false));
答案 1 :(得分:0)
您可以使用List<String> listString = ["true", "false", "true"];
List<bool> listBool = listString.map((e) => e == "true").toList();
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const Pool = require("pg").Pool;
const pool = new Pool({
user: "mgr@stanpgtest",
host: "stanpgtest.postgres.database.azure.com",
database: "my db name",
password: "my pass",
port: 5432
});
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.listen(8000, () => {
console.log(`Server is running, listening to port 8000`);
});
app.post("/api/v1/nodo2059e7", (req, res) => {
const { label, status, priority } = req.body;
pool.query(
"select now()",
(error, results) => {
if (error) {
throw error;
}
res.send(results);
}
);
});