【问题标题】:SharePoint Column Formatting using JSON使用 JSON 的 SharePoint 列格式
【发布时间】:2018-04-18 02:06:02
【问题描述】:

我正在尝试使用 JSON 格式化列表中的列,我想从字段中删除“mailto:”并在字段值前面添加一个小邮件图标。

我得到了添加邮件图标的 JSON(最后,在字段值之后 - 第一次尝试还不错),但没有运气从字段中删除“mailto:”,有什么建议吗?

{
    "debugMode": true,
    "elmType": "div",
    "children": [
        {
            "elmType": "div",
            "style": {
                "padding-right": "8px"
            },
            "txtContent": "@currentField"
        },
        {
            "elmType": "a",
            "attributes": {
                "iconName": "Mail",
                "class": "sp-field-quickActions",
                "href": "@currentField"
            }
        }
    ]
}

【问题讨论】:

  • 您使用的是人员/组字段还是普通文本字段?
  • 它是一个超链接字段,它将链接存储为“mailto:username@domain.com”
  • 您将“mailto”存储在文本中,据我所知,无法通过 json 替换它。你不能使用人员/组字段吗?
  • 这个字段是超链接的原因有很多,当它包含“mailto:”时,JSON将替换内容以显示一个漂亮的小信封,或者当内容为“www”时替换为地球仪”,或者像“share:\\”这样的服务器-我刚刚开始使用mailto:看看我能在这条路上走多远,也许不会太远,但我仍在尝试了解 JSON 的来龙去脉
  • 我仍然不确定你想要达到什么目的。根据方案,提供的 json 无效。也看看这个:sharepointing.co.uk/2017/11/10/…

标签: json formatting sharepoint-online


【解决方案1】:

如果您使用标准的新建/编辑表单,超链接字段会要求提供 URL 和显示文本。如果您的显示文本是人名(或除 href 之外的任何字符串),您可以简单地更新 txtContent 如下:

"txtContent": "@currentField.desc"

如果过渡,你可能想要使用

"txtContent": "=if(@currentField.desc!='',@currentField.desc,@currentField)"

一个完整的解决方案,包括您希望在值可能读取之前放置图标

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "a",
      "attributes": {
        "iconName": "Mail",
        "class": "sp-field-quickActions",
        "href": "@currentField"
      },
      "style": {
        "display": "=if(@currentField!='', 'block','none !important')",
        "padding-right": "8px"
      }
    },
    {
      "elmType": "div",
      "txtContent": "=if(@currentField.desc!='',@currentField.desc,@currentField)"
    }
  ]
}

由于您没有说明该字段是否为必填项,因此我添加了一种显示样式以在该字段为空时省略显示图标

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多