随机生成的十六进制颜色的树枝
问题描述:
我想产生的树枝随机十六进制的颜色,在一些使用它,例如作为背景是这样的:随机生成的十六进制颜色的树枝
{% for organization in organizations %}
{
value: {{ organization.value }},
color: "#F56954",
label: "{{ organization.name }}"
},
{% endfor %}
任何方式做到这一点?
答
我建议你去随机化一个专门设置的数据(以排除没有意义的值)如下:
{% for organization in organizations %}
{
value: {{ organization.value }},
color: "{{ random(['#H54924', '#F36252', '#F56954']) }}"
label: "{{ organization.name }}"
},
{% endfor %}
编辑:
对于纯粹的随机值,你可以试试下面的办法:
{% set values = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']%}
{% for organization in organizations %}
{
value: {{ organization.value }},
color: "#{{random(values)~ random(values)~ random(values)~ random(values)~ random(values)~ random(values) }}",
label: "{{ organization.name }}"
},
{% endfor %}
{{ '#' ~ random(values) ~ random(values) ~ random(values) ~ random(values) ~ random(values) ~ random(values) }}
Here工作的例子
希望这个帮助