SharePoint Online-“人员”列自定义-在空白字段上隐藏占位符图像

时间:2019-04-02 13:24:00

标签: json sharepoint

我一直在尝试使用“人物”(People)列类型使个人资料图片显示在SharePoint的现代列表中,这在经典SharePoint中工作正常,但在现代列表中却没有。因此,我转向使用JSON和here(下面的相同代码)中的示例来自定义列

###############################
#     #                       #
####  #  ####  #############  #
#  #  #  #     #     #     #  #
#  #  ####  ####  #  #  ####  #
#  #     #  #     #     #     #
#  ####  #  ####  ####  #  ####
#     #     #     #     #  #  #
#  #  #######  ####  ####  #  #
#  #     #        #     #  #  #
#  #  ####  ####  #######  #  #
#  #  #     #  #        #     #
#  ####  ####  #######  ####  #
#  #     #        #        #  #
#  #  ####  #######  #######  #
#     #     #        #        #
#  #######  #  #######  #######
#     #     #     #     #     #
####  #  #  ####  #  #######  #
#        #     #              #
###############################

这非常有用,不同之处在于,如果该字段为空,则使用默认的个人资料图片占位符图像填充该字段,如您在此处看到的

People column showing default place holders

我的问题是我有什么办法可以抑制这张图片,因此,如果该字段为空,则列表视图上为空?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试一下。

enter image description here

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "div",
      "style": {
        "width": "32px",
        "height": "32px",
        "overflow": "hidden",
        "border-radius": "50%"
      },
      "children": [
        {
          "elmType": "img",
          "attributes": {
            "src": "=if(length(@currentField.email)==0, '', '/_layouts/15/userphoto.aspx?size=S&accountname=' + @currentField.email)",
            "title": "=if(length(@currentField.email)==0,'',@currentField.Title)"
          },
          "style": {
            "position": "relative",
            "top": "50%",
            "left": "50%",
            "width": "100%",
            "height": "auto",
            "margin-left": "-50%",
            "margin-top": "-50%"
          }
        }
      ]
    }
  ]
}