干净地排列清单项目 dash

问题描述 投票:0回答:1

我使用plotly dash 开发仪表板,需要显示包含大约60 个选项的清单。然而,数量不是固定的,因此必须动态地排列选项。我正在使用:

dcc.Checklist(
   id="checklist",
   options=possible_fields,
   value=[],
   inline=True,
)

不幸的是,选项标签的长度并不总是相同,这会导致外观不干净:

🗸 ab 🗸 acd 🗸 ad
🗸 a 🗸 abcd 🗸 ae
🗸 abc 🗸 acdc 🗸 af

如何动态、干净地排列选项?例如

🗸 ab  🗸 acd  🗸 ad
🗸 a   🗸 abcd 🗸 ae
🗸 abc 🗸 acdc 🗸 af
python plotly plotly-dash
1个回答
0
投票
possible_fields = ['a', 'aaa', 'aam', 'aaaaa']

lengths = [len(s) for s in possible_fields]
largest_length = max(lengths)

possible_fields = [ s.ljust(largest_length, " ") for s in possible_fields ]

这样的东西应该让你的

possible_fields
数组中的字符串都具有相同数量的字符,并在右侧用空格填充。

© www.soinside.com 2019 - 2024. All rights reserved.