You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SharePoint列格式化:超链接列空值判断控制字段显隐异常

SharePoint列格式化显隐逻辑修复方案

问题分析

你提供的JSON代码存在两个核心问题:

  • 语法错误:if函数缺少闭合的右括号),导致格式解析失败
  • 逻辑颠倒:当前逻辑是Link列为空时显示,非空时隐藏,若你的需求是反过来(Link列有值时显示目标列,空时隐藏),则逻辑完全写反了

正确代码示例

假设你的需求是:当「Link to Site」列不为空时显示当前列,为空时隐藏,修正后的JSON代码如下:

{
  "$schema": "https://developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "color": "#0078d7",
    "display": "=if([$Link_x0020_to_x0020_Site] != '', 'block', 'none')"
  },
  "txtContent": "@currentField"
}

如果你的需求是当「Link to Site」列为空时显示当前列,非空时隐藏,则调整if条件:

{
  "$schema": "https://developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "color": "#0078d7",
    "display": "=if([$Link_x0020_to_x0020_Site] == '', 'block', 'none')"
  },
  "txtContent": "@currentField"
}

额外说明

  • 你使用的Link_x0020_to_x0020_Site是正确的列内部名称,无需修改
  • 若直接判断空字符串无效(超链接列本质是对象类型),可尝试判断URL属性:=if([$Link_x0020_to_x0020_Site.url] == '', 'block', 'none')

内容的提问来源于stack exchange,提问作者Chris Eaheart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 11:35:22