首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改列格式的当前代码以包括图标

更改列格式的当前代码以包括图标
EN

Stack Overflow用户
提问于 2019-09-24 04:07:55
回答 1查看 1.2K关注 0票数 0

我希望有人能提供帮助--我对JSON或编码不太了解。

我有一个sharepoint联机列表,我已经格式化了它,根据每个项目中显示的文本显示不同的颜色。我现在也希望将图标添加到列中。例如,如果状态为New,我希望它是我在代码中选择的颜色,但同时也添加了Office中的+图标。

下面是我使用过的两个代码,它们分别工作,我想将它们连接在一起。

代码语言:javascript
复制
    {
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "=if(@currentField == 'Completed', 'CheckMark', if(@currentField == 'Draft phase', 'Forward', if(@currentField == 'Approval phase', 'Error', if(@currentField == 'On hold', 'Warning', 'ErrorBadge'))))"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

代码语言:javascript
复制
   {
  "elmType": "div",
  "style": {
    "padding": "0 4px"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            {
              "operator": "toLowerCase",
              "operands": [
                "@currentField"
              ]
            },
            {
              "operator": "toLowerCase",
              "operands": [
                "New"
              ]
            }
          ]
        },
        "sp-css-backgroundColor-blueBackground07",
        {
          "operator": ":",
          "operands": [
            {
              "operator": "==",
              "operands": [
                {
                  "operator": "toLowerCase",
                  "operands": [
                    "@currentField"
                  ]
                },
                {
                  "operator": "toLowerCase",
                  "operands": [
                    "Draft phase"
                  ]
                }
              ]
            },
            "sp-css-backgroundColor-warningBackground",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    {
                      "operator": "toLowerCase",
                      "operands": [
                        "@currentField"
                      ]
                    },
                    {
                      "operator": "toLowerCase",
                      "operands": [
                        "Approval phase"
                      ]
                    }
                  ]
                },
                "sp-css-backgroundColor-successBackground",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        {
                          "operator": "toLowerCase",
                          "operands": [
                            "@currentField"
                          ]
                        },
                        {
                          "operator": "toLowerCase",
                          "operands": [
                            "Ready for upload"
                          ]
                        }
                      ]
                    },
                    "sp-css-backgroundColor-blockingBackground",
                    {
                      "operator": ":",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            {
                              "operator": "toLowerCase",
                              "operands": [
                                "@currentField"
                              ]
                            },
                            {
                              "operator": "toLowerCase",
                              "operands": [
                                "Completed"
                              ]
                            }
                          ]
                        },
                        "sp-css-backgroundColor-neutralBackground",
                        {
                          "operator": ":",
                          "operands": [
                            {
                              "operator": "==",
                              "operands": [
                                {
                                  "operator": "toLowerCase",
                                  "operands": [
                                    "@currentField"
                                  ]
                                },
                                {
                                  "operator": "toLowerCase",
                                  "operands": [
                                    "On hold"
                                  ]
                                }
                              ]
                            },
                            "sp-css-backgroundColor-errorBackground",
                            ""
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "txtContent": "@currentField"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-24 07:03:48

尝尝这个。

代码语言:javascript
复制
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "padding": "0 4px"
  },
  "attributes": {
    "class": {
      "operator": ":",
      "operands": [
        {
          "operator": "==",
          "operands": [
            {
              "operator": "toLowerCase",
              "operands": [
                "@currentField"
              ]
            },
            {
              "operator": "toLowerCase",
              "operands": [
                "New"
              ]
            }
          ]
        },
        "sp-css-backgroundColor-blueBackground07",
        {
          "operator": ":",
          "operands": [
            {
              "operator": "==",
              "operands": [
                {
                  "operator": "toLowerCase",
                  "operands": [
                    "@currentField"
                  ]
                },
                {
                  "operator": "toLowerCase",
                  "operands": [
                    "Draft phase"
                  ]
                }
              ]
            },
            "sp-css-backgroundColor-warningBackground",
            {
              "operator": ":",
              "operands": [
                {
                  "operator": "==",
                  "operands": [
                    {
                      "operator": "toLowerCase",
                      "operands": [
                        "@currentField"
                      ]
                    },
                    {
                      "operator": "toLowerCase",
                      "operands": [
                        "Approval phase"
                      ]
                    }
                  ]
                },
                "sp-css-backgroundColor-successBackground",
                {
                  "operator": ":",
                  "operands": [
                    {
                      "operator": "==",
                      "operands": [
                        {
                          "operator": "toLowerCase",
                          "operands": [
                            "@currentField"
                          ]
                        },
                        {
                          "operator": "toLowerCase",
                          "operands": [
                            "Ready for upload"
                          ]
                        }
                      ]
                    },
                    "sp-css-backgroundColor-blockingBackground",
                    {
                      "operator": ":",
                      "operands": [
                        {
                          "operator": "==",
                          "operands": [
                            {
                              "operator": "toLowerCase",
                              "operands": [
                                "@currentField"
                              ]
                            },
                            {
                              "operator": "toLowerCase",
                              "operands": [
                                "Completed"
                              ]
                            }
                          ]
                        },
                        "sp-css-backgroundColor-neutralBackground",
                        {
                          "operator": ":",
                          "operands": [
                            {
                              "operator": "==",
                              "operands": [
                                {
                                  "operator": "toLowerCase",
                                  "operands": [
                                    "@currentField"
                                  ]
                                },
                                {
                                  "operator": "toLowerCase",
                                  "operands": [
                                    "On hold"
                                  ]
                                }
                              ]
                            },
                            "sp-css-backgroundColor-errorBackground",
                            ""
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": "=if(@currentField == 'Completed', 'CheckMark', if(@currentField == 'Draft phase', 'Forward', if(@currentField == 'Approval phase', 'Error', if(@currentField == 'On hold', 'Warning', 'ErrorBadge'))))"
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58072975

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档