首页 > 解决方案 > SharePoint 查找字段格式链接到列表项其引用

问题描述

所以我有两个 SharePoint 列表: 1. 学生:- 姓名 - ... - ... 2. 公司:- ... - 学生(查找字段,学生列表)

我想格式化这个“学生姓名”字段,更改文本颜色和背景颜色。这有效,但现在该字段不再可点击。如果我删除自定义格式,我可以单击该字段值,它会将我带到该学生的详细信息。

我试图在格式化 json 上添加 href 属性,但它不起作用,我无法单击它。

这就是我得到的:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField.lookupValue",
"attributes": {
  "target": "_blank",
  "href": "='/sites/xxxx/Lists/Student/DispForm.aspx?Name=' + [$Student]"
},
"style": {
  "color": "#796BB1",
  "font-weight": "bold"
}

}

我还尝试将链接更改为“www.google.com”,以防该项目的链接错误。

标签: jsonsharepointformatlookup

解决方案


对于超链接,elmType 应该是“a”而不是“div”。你可以试试下面的代码:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField.lookupValue",
 "attributes": {
      "href": {
         "operator": "+",
         "operands": [
            "/sites/michael/Lists/Student/DispForm.aspx?ID=",
            "@currentField.lookupId"
         ]
      },
      "target": "_blank"
   },
"style": {
  "color": "#796BB1",
  "font-weight": "bold"
}
}

推荐阅读