SharePoint 查找字段格式 link 以列出其引用的项目

SharePoint lookup field format link to list item its referencing

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

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

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

这是我得到的:

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

}

我还尝试将 link 更改为 'www.google.com',以防该项目的 link 错误。

对于超链接,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"
}
}