【问题标题】:Formatting Sharepoint columns with JSON使用 JSON 格式化 Sharepoint 列
【发布时间】:2019-01-28 05:28:56
【问题描述】:

我正在为我工​​作的一家仓库公司创建一个 Sharepoint 列表。该列表包含仓库 1-94 的所有过道。

过道分为不同的部门,

  • 杂货 (51-94),冷冻 (1-16)
  • 熟食店(17-23, 25, 36-39)
  • 生产(24,26-34)

我需要杂货店过道是一种颜色,冷冻成另一种颜色等等。我有一些从这里找到的代码。

https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

但是,我不知道如何让过道 25 成为熟食店的颜色或 24 成为生产颜色,因为它们不属于 >=、

{
"elmType": "div",
"txtContent": "@currentField",
"style": {
    "color": "#000000",
    "padding-left": "14px",
    "background-color": {
        "operator": "?",
        "operands": [
            {
                "operator": ">=",
                "operands": [
                    "@currentField",
                    51
                ]
            },
            "#e5e5e5",
            {
                "operator": "?",
                "operands": [
                    {
                        "operator": ">=",
                        "operands": [
                            "@currentField",
                            24
                        ]
                    },
                    "#91ff94",
                    {
                        "operator": "?",
                        "operands": [
                            {
                                "operator": ">=",
                                "operands": [
                                    "@currentField",
                                    17
                                ]
                            },
                            "#fbff93",
                            {
                                "operator": "?",
                                "operands": [
                                    {
                                        "operator": "<=",
                                        "operands": [
                                            "@currentField",
                                            16
                                        ]
                                    },
                                    "#91d2ff",
                                    ""
                                ]
                            } ,
                            {
                                "operator": "?",
                                "operands": [
                                    {
                                        "operator": "==",
                                        "operands": [
                                            "@currentField",
                                            25
                                        ]
                                    },
                                    "#91d2ff",
                                    ""
                                ]
                            } 
                        ]
                    }
                ]
            }
        ]
    }
}

}

另外,任何人都知道我是否可以将列表的标题更改为 数值而不是一行文本?

【问题讨论】:

    标签: json list sharepoint formatting


    【解决方案1】:

    多个条件示例供您参考。

        {
      "elmType":"div",
      "txtContent":"@currentField",
      "style":{
      "color": {
          "operator": "?",
          "operands": [
                {   
                  "operator":"||",
                  "operands":[
                   { "operator": "&&", "operands":[
                        { "operator": ">=", "operands": ["@currentField", 17] },
                        { "operator": "<=", "operands": ["@currentField", 23] }
                        ] },
                   { "operator": "&&", "operands":[
                        { "operator": ">=", "operands": ["@currentField", 36] },
                        { "operator": "<=", "operands": ["@currentField", 39] }
                        ] } 
                  ]
             },
             "red",
             {
                "operator": "?",
                "operands": [
                        {
                            "operator": "==",
                            "operands": [
                                "@currentField",
                                25
                            ]
                        },
                    "red",
                    "blue"
                ]
            }
          ]
        }
      }
    }
    

    【讨论】:

    • 非常感谢!正是我需要的!
    【解决方案2】:

    根据您的数据结构,您可以使用“选择”列类型将元数据分配给每条记录。这将简化您的整体实施。

    现在,对于 Choice、Date/Time 和 Boolean 列类型还有一个无代码解决方案,无需了解复杂的 JSON 知识即可分配背景颜色。

    No Code Column Formatting – SharePoint Online

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 2021-09-01
      相关资源
      最近更新 更多