Изменить текущий код для форматирования столбца, чтобы включить значки - PullRequest
0 голосов
/ 24 сентября 2019

Я надеюсь, что кто-то может помочь - я совсем немного знаю о JSON или кодировании.

У меня есть сетевой список sharepoint, который я отформатировал, чтобы отображать разные цвета в зависимости от того, какой текст отображается в каждом элементе.Теперь я хочу добавить значки в столбцы.Например, если статус «Новый», я хочу, чтобы он был цветом, который я выбрал в коде, но также добавил значок «+» в Office UI Fabric.

Ниже приведены два кода, которые я использовал, они работают отдельно, я хочу объединить их.

    {
  "$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"
    }
  ]
}

   {
  "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"
}

1 Ответ

0 голосов
/ 24 сентября 2019

Попробуйте это.

enter image description here

{
  "$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"
    }
  ]
}
...