JSON 中的多个格式化条件
Multiple formating conditions in JSON
我正在尝试为我的 SharePoint 列表使用一个简单的格式,方法是使用 JSON 根据行索引和“批准状态”来格式化颜色,一个简单的逻辑如下:
If the status is approved:
for each devise the index by 2 and if the reminder is equal to 0 show a slightly lighter color
,otherwise a darker color (pretty standard formatting)
If the status is not Approved
if Status is Pending, use orange
if status is Rejected, use red
基于行索引的着色效果很好,状态着色也很好,但不能将两者放在一起。
{
"additionalRowClass": {
"operator": ":",
"operands": [
{
"operator": "&&", "operands": [
{ "operator": "==", "operands": ["[$_ModerationStatus]","Approved"] },
"operator": "==",
"operands": [
{
"operator": "%",
"operands": [
"@rowIndex",
2
]
},
0
]
]
},
"sp-css-backgroundColor-neutralBackground",
{
"operator": ":",
"operands": [
{
"operator": "&&", "operands": [
{ "operator": "==", "operands": ["[$_ModerationStatus]","Approved"] },
"operator": "==",
"operands": [
{
"operator": "%",
"operands": [
"@rowIndex",
2
]
},
1
]
},
"sp-css-backgroundColor-noFill",
""
]
}
}
}
下面是我的演示JSON代码供大家参考:
{
"schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass":"=if([$Status]=='Approved',if(@rowIndex%2==0,'sp-css-backgroundColor-neutralBackground','sp-css-backgroundColor-noFill'),if([$Status]=='Pending','ms-bgColor-orangeLight',if([$Status]=='Rejected','ms-bgColor-red',''))"
}
测试结果:
我正在尝试为我的 SharePoint 列表使用一个简单的格式,方法是使用 JSON 根据行索引和“批准状态”来格式化颜色,一个简单的逻辑如下:
If the status is approved:
for each devise the index by 2 and if the reminder is equal to 0 show a slightly lighter color
,otherwise a darker color (pretty standard formatting)
If the status is not Approved
if Status is Pending, use orange
if status is Rejected, use red
基于行索引的着色效果很好,状态着色也很好,但不能将两者放在一起。
{
"additionalRowClass": {
"operator": ":",
"operands": [
{
"operator": "&&", "operands": [
{ "operator": "==", "operands": ["[$_ModerationStatus]","Approved"] },
"operator": "==",
"operands": [
{
"operator": "%",
"operands": [
"@rowIndex",
2
]
},
0
]
]
},
"sp-css-backgroundColor-neutralBackground",
{
"operator": ":",
"operands": [
{
"operator": "&&", "operands": [
{ "operator": "==", "operands": ["[$_ModerationStatus]","Approved"] },
"operator": "==",
"operands": [
{
"operator": "%",
"operands": [
"@rowIndex",
2
]
},
1
]
},
"sp-css-backgroundColor-noFill",
""
]
}
}
}
下面是我的演示JSON代码供大家参考:
{
"schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass":"=if([$Status]=='Approved',if(@rowIndex%2==0,'sp-css-backgroundColor-neutralBackground','sp-css-backgroundColor-noFill'),if([$Status]=='Pending','ms-bgColor-orangeLight',if([$Status]=='Rejected','ms-bgColor-red',''))"
}
测试结果: