首页 > 解决方案 > SharePoint 列格式 - 可能是大写或小写文本的条件?

问题描述

我有一个 SharePoint 列表,其中有一列是从 MS 表单填充的,用户填写的字段是自由文本,但他们需要在框中输入最少的 n/a。如果内容不是 n/a,我尝试使用的格式将更改字段红色的背景。由于 JSON 区分大小写,我需要能够同时检查 n/a 和 N/A,我找到了使用 (ToLowerCase) 的参考,但我对 JSON 的有限知识在这里对我没有帮助。

当前 JSON

{
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "!=",
          "operands": [
            "@currentField",
            "n/a"
          ]
        },
        "sp-css-backgroundColor-errorBackground50",
        ""
      ]
    }
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "line-height": "16px",
        "height": "14px"
      },
      "attributes": {
        "iconName": {
          "operator": ":",
          "operands": [
            {
              "operator": "!=",
              "operands": [
                "@currentField",
                "n/a"
              ]
              ]
            },
            "",
            ""
          ]
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "overflow": "hidden",
        "text-overflow": "ellipsis",
        "padding": "0 3px"
      },
      "txtContent": "@currentField",
      "attributes": {
        "class": {
          "operator": ":",
          "operands": [
            {
              "operator": "!=",
              "operands": [
                "@currentField",
                "n/a"
              ]
            },
            "",
            ""
          ]
        }
      }
    }
  ]
}

任何帮助将不胜感激。

谢谢罗伯

标签: jsonsharepoint-online

解决方案


您可以尝试以下格式。

在此处输入图像描述

{
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px"
  },
  "attributes": {
                "class": "=if(toLowerCase(@currentField) != 'n/a', 'sp-css-backgroundColor-errorBackground50', '')"
            },
  "children": [
    {
      "elmType": "span",
      "style": {
        "line-height": "16px",
        "height": "14px"
      },
      "attributes": {
        "iconName": {
          "operator": ":",
          "operands": [
            {
              "operator": "!=",
              "operands": [
                "@currentField",
                "n/a"
              ]              
            },
            "",
            ""
          ]
        }
      }
    },
    {
      "elmType": "span",
      "style": {
        "overflow": "hidden",
        "text-overflow": "ellipsis",
        "padding": "0 3px"
      },
      "txtContent": "@currentField",
      "attributes": {
        "class": {
          "operator": ":",
          "operands": [
            {
              "operator": "!=",
              "operands": [
                "@currentField",
                "n/a"
              ]
            },
            "",
            ""
          ]
        }
      }
    }
  ]
  }

推荐阅读