Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数据库模板增加一个可访问的字段,获取当前条目所有字段的 id、名称、类型 #14171

Open
TCOTC opened this issue Feb 21, 2025 · 1 comment

Comments

@TCOTC
Copy link
Contributor

TCOTC commented Feb 21, 2025

通过这个字段可以获取当前条目的所有字段的 id、名称、类型

{
  "字段1的id": ["字段1的名称", "字段1的类型"],
  "字段2的id": ["字段2的名称", "字段2的类型"],
  "字段3的id": ["字段3的名称", "字段3的类型"],
  "字段4的id": ["字段4的名称", "字段4的类型"]
}
{
  "field1": ["Name1", "Type1"],
  "field2": ["Name2", "Type2"],
  "field3": ["Name3", "Type3"],
  "field4": ["Name4", "Type4"]
}

然后就能实现:

  1. 获取所有复选框字段,统计总数
  2. 判断各个复选框是否勾选,统计勾选数
  3. 计算得出勾选比例

或者别的什么方案也行,目的是能获取到条目的所有字段的 id、名称、类型


目前想要实现类似的逻辑会非常繁琐且不通用:

Image

.action{$total:= 4} .action{/* 填列数 */}
.action{$count:= 0}

.action{/* 有多少列就填多少组 */}
.action{$state1:= index . "早起"}
.action{$state2:= index . "运动"}
.action{$state3:= index . "阅读"}
.action{$state4:= index . "日报"}

.action{if eq $state1 "√"}
.action{$count = add1 $count}
.action{end}

.action{if eq $state2 "√"}
.action{$count = add1 $count}
.action{end}

.action{if eq $state3 "√"}
.action{$count = add1 $count}
.action{end}

.action{if eq $state4 "√"}
.action{$count = add1 $count}
.action{end}


.action{$width:= floor (mulf (divf $count $total) 100)}
.action{$transparency:= addf (mulf (divf $count $total) 0.8) 0.2}

<div style="display: flex; justify-content: flex-end; height: 100%;">
<span style="font-size: 100%; margin-right: 4px;">.action{$width}%</span>
<span style="background-color: rgba(175,184,193,0.2); width: 100%; display: inline-block;height: 12px;border-radius: 6px;align-self: center;overflow: hidden;">
    <span style="text-align: right; font-size: 12px; width: .action{$width}%; background-color: rgba(45,164,78,.action{$transparency}); display: inline-block;height: inherit;vertical-align: top;"></span>
</span>
</div>
@TCOTC
Copy link
Contributor Author

TCOTC commented Feb 21, 2025

最好还能通过字段的 id 来获取字段值 #11237 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant