效果图:
<!--
* @Descripttion:
* @version:
* @Author: mqq
* @Date: 2021-03-19 18:17:46
* @LastEditors: mqq
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
/**
* @descripttion: 键值对-----对应关系转换
* @param {*} operation 关系表
* @param {*} flag true 进行转换,否则不转换
* @return {*}
*/
function relationalTable(operation, flag = true) {
let titleObj = {
1: "标题+正文",
2: "标题+摘要",
3: "仅标题",
};
let xuhaoObj = {
1: "时间降序",
2: "时间升序",
3: "热度值排序",
4: "优先标题排序",
};
let newObj = {};
const obj = typeof operation === 'boolean' ? {} : eval(operation + "Obj") // 防止operation未传,拼接报错
for (const [key, value] of Object.entries(obj)) {
flag ? (newObj[value] = key) : (newObj[key] = value);
}
return newObj;
}
console.log(relationalTable('xuhao', true));
</script>
</body>
</html>