如何使用JSON在sharepoint中显示多选选择列的自定义标题?

时间:2019-04-05 00:59:44

标签: json sharepoint

我在SharePoint的多项选择栏中有首字母缩写词。 我想显示描述首字母缩略词的标题。例如,当我将鼠标悬停在ATZ上时,也许我想让它说“在The Zoo-ATZ”。
我只是在学习使用它,似乎无法找到一种为循环中的每个$ ChoiceIterator分配字符串的方法。我可以将$ ChoiceIterator放在标题中,但是我想为每个标题添加唯一的描述。

谢谢!

我已经尝试过https://github.com/SharePoint/sp-dev-list-formatting/tree/master/column-samples/multi-choice-icons网站上的示例

在“标题”之后使用此代码段:并尝试正确插入我的$ ChoiceIterator。

"=if(indexOf(join(@currentField,''),'dog') != -1, 'Yes', 'No')

但是结果很简单,就是每次选择图标时都显示相同的文本。

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "forEach": "choiceIterator in @currentField",
      "elmType": "div",
      "txtContent": "[$choiceIterator]",
      "attributes": {
        "class": "ms-bgColor-themePrimary ms-fontColor-white",
        "title": "='This should describe the license... ' + [$choiceIterator]"
      },
      "style": {
        "width": "27px",
        "height": "16px",
        "text-align": "center",
        "margin": "2px"
      }
    }
  ]
}

2 个答案:

答案 0 :(得分:0)

跨度使用标题作为工具提示,因此您可以将标题设置为每个跨度的详细说明。

enter image description here

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "font-size": "16px"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "title": "Water Description",
        "iconName": "Precipitation",
        "class": "='ms-fontColor-' + if(indexOf(join(@currentField,''),'Water') != -1, 'themeDark', 'neutralLight')"
      },
      "style": {
        "padding": "0 2px"
      }
    },
    {
      "elmType": "span",
      "attributes": {
        "title": "Coffee Description",
        "iconName": "CoffeeScript",
        "class": "='ms-fontColor-' + if(indexOf(join(@currentField,''),'Coffee') != -1, 'themeDark', 'neutralLight')"
      },
      "style": {
        "padding": "0 2px 0 0"
      }
    },
    {
      "elmType": "span",
      "attributes": {
        "title": "Wine Description",
        "iconName": "Wines",
        "class": "='ms-fontColor-' + if(indexOf(join(@currentField,''),'Wine') != -1, 'themeDark', 'neutralLight')"
      },
      "style": {
        "padding": "0 2px"
      }
    },
    {
      "elmType": "span",
      "attributes": {
        "title": "Beer Description",
        "iconName": "BeerMug",
        "class": "='ms-fontColor-' + if(indexOf(join(@currentField,''),'Beer') != -1, 'themeDark', 'neutralLight')"
      },
      "style": {
        "padding": "0 2px"
      }
    },
    {
      "elmType": "span",
      "attributes": {
        "title": "\"Juice Description more...\"",
        "iconName": "MusicInCollectionFill",
        "class": "='ms-fontColor-' + if(indexOf(join(@currentField,''),'\"Juice\"') != -1, 'themeDark', 'neutralLight')"
      },
      "style": {
        "padding": "0 2px"
      }
    }
  ]
}

您可以使用许多图标。

https://developer.microsoft.com/en-us/fabric#/styles/icons#icons

答案 1 :(得分:0)

因此上述答案有效,但始终显示所有图标。就我而言,我不需要图标,我希望能够在我的多项选择列上创建并选择自定义首字母缩写词。

为使示例简单: 我有一行客户清单。一栏是客户购买产品的自定义功能的多种选择。

有3个带有长名称的自定义选项。 长棕玉米 大橙色牛 宽粉色Biskit

如果客户具有所有3个功能,那么我不想用这些长名称挤满我的专栏。因此,我想将它们显示为鼠标悬停时带有弹出式标题的缩写。 LBC,BOC,WPB

此行末尾的通知,您需要额外的空白引号”。我认为这是IF声明的ELSE部分。

“ title”:“ = if([$ choiceIterator] =='BOC','Big Orange Cow',if([$$ iceiceIterator] =='LBC','长棕玉米',if([$$ iceIterator ] =='WPB','Wide Pink Biskit','')“

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "forEach": "choiceIterator in @currentField",
      "elmType": "div",
      "txtContent": "[$choiceIterator]",
      "attributes": {
        "class": "ms-bgColor-themePrimary ms-fontColor-white",
        "title": "= if([$choiceIterator] == 'BOC', 'Big Orange Cow', if([$choiceIterator] == 'LBC', 'Long Brown Corn', if([$choiceIterator] == 'WPB', 'Wide Pink Biskit', '' )"
      },
      "style": {
        "width": "28px",
        "height": "16px",
        "text-align": "center",
        "margin": "2px"
      }
    }
  ]
}