使用字段格式化来自定义SharePoint(二)

博客地址:http://blog.csdn.net/FoxDave

应用条件性的格式化

我们可以使用字段格式化去应用样式、类(CSS)和图标到字段上,取决于这些字段的值。

基于数字范围的条件格式化 (基本)
下图展示了应用条件格式化到数字范围的示例。
这里写图片描述
本示例使用条件运算符?,在当前字段的值小于等于70时,去应用类(sp-field-severity–warning)到父DIV元素。这使得该字段在值小于等于70时高亮显示,大于70时正常显示。

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "debugMode": true,
    "elmType": "div",
    "attributes": {
       "class": {
          "operator": "?",
          "operands": [
             {
                "operator": "<=",
                "operands": [
                   "@currentField",
                   70
                ]
             },
             "sp-field-severity--warning",
             ""
          ]
       }
    },
    "children": [
        {
            "elmType": "span",
            "style": {
                "display": "inline-block",
                "padding": "0 4px"
            },
            "attributes": {
                "iconName": {
                    "operator": "?",
                    "operands": [
                        {
                            "operator": "<=",
                            "operands": [ "@currentField", 70 ] },
                        "Error",
                        ""
                    ]
                }
            }
        },
        {
            "elmType": "span",
            "txtContent": "@currentField"
        }
    ]
}

基于文本或选项字段值的条件格式化 (高级)
下图展示了应用条件格式化到文本或选项类型字段的例子:
这里写图片描述
我们可以应用条件格式化到可能包含固定值集合的文本或选项类型的字段。下面的示例基于字段的值是否是”Done”、”In Review”、”Blocked”或其他值来应用不同的样式类。本示例基于字段的值应用CSS类 (sp-field-severity–low, sp-field-severity–good, sp-field-severity–warning, sp-field-severity–blocked)到DIV元素。然后它会输出一个SPAN元素,带有IconName属性。这个属性会应用另一个CSS类到SPAN元素,显示一个Office UI Fabric图标在里面。最后,另一个包含字段值的SPAN元素被输出。
本模式在我们想要不同的值映射到不同的紧迫性或严重程度的优先级时很有用。我们可以基于本例进行编辑以适应我们自己的需求。

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "debugMode": true,
    "elmType": "div",
    "attributes": {
        "class": {
            "operator": "?",
            "operands": [
                {
                    "operator": "==",
                    "operands": [
                        {
                            "operator": "toString()",
                            "operands": [ "@currentField" ] },
                        "Done"
                    ]
                },
                "sp-field-severity--good",
                {
                    "operator": "?",
                    "operands": [
                        {
                            "operator": "==",
                            "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "In progress" ] },
                        "sp-field-severity--low",
                        {
                            "operator": "?",
                            "operands": [ { "operator": "==", "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "In review" ] }, "sp-field-severity--warning", { "operator": "?", "operands": [ { "operator": "==", "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "Blocked" ] }, "sp-field-severity--severeWarning", "sp-field-severity--blocked" ] } ] }
                    ]
                }
            ]
        }
    },
    "children": [
        {
            "elmType": "span",
            "style": {
                "display": "inline-block",
                "padding": "0 4px"
            },
            "attributes": {
                "iconName": {
                    "operator": "?",
                    "operands": [
                        {
                            "operator": "==",
                            "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "Done" ] },
                        "CheckMark",
                        {
                            "operator": "?",
                            "operands": [ { "operator": "==", "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "In progress" ] }, "Forward", { "operator": "?", "operands": [ { "operator": "==", "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "In review" ] }, "Error", { "operator": "?", "operands": [ { "operator": "==", "operands": [ { "operator": "toString()", "operands": [ "@currentField" ] }, "Has issues" ] }, "Warning", "ErrorBadge" ] } ] } ] }
                    ]
                }
            }
        },
        {
            "elmType": "span",
            "txtContent": "@currentField"
        }
    ]
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值