json - 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”,以防该项目的链接错误。
解决方案
对于超链接,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"
}
}
推荐阅读
- java - 在文件选择器中包含我自己的示例图片(Intent.ACTION_PICK)
- javascript - 如何在javascript中创建对象数组?
- mongodb - 一些MongoDB聚合时如何保留旧字段?
- android - Google Play In-app Billing API 版本低于 3 并更新了 Play Store
- cluster-computing - 如何在 R 中的稀疏相关矩阵上应用层次聚类(NaN 相异值)?
- django - 为什么我们需要“序列化”模型字段属性?
- python - 为什么 Pythonw 文件占用大量 CPU 资源?
- sql - 在创建过程 pl sql 中返回布尔值
- c - 设置私有后设置公钥的目的是什么?
- svelte - 在 svelte 中基于对象创建组件