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

SharePoint列表格式化异常求助:按Ganztägig字段控制内容显示

SharePoint列表列格式化失效问题修复方案

原代码存在的问题

  • 布尔值判断逻辑错误:Ganztägig作为复选框字段,直接调用[$Ganztägig]即可获取布尔值;若使用.displayValue,返回的是字符串"TRUE"/"FALSE",不能直接和布尔值TRUE做比较。
  • 未满足需求中的显示要求:原代码仅返回日期,未添加指定的“ganztägig”字样。
  • 冗余括号可能影响代码解析。

修正后的格式化代码

方案一(推荐,直接使用字段布尔值)

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Ganztägig], toLocaleDateString(@currentField) + ' ganztägig', toLocaleString(@currentField))"
}

方案二(针对字段值为字符串的特殊场景)

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if([$Ganztägig.displayValue] == 'TRUE', toLocaleDateString(@currentField) + ' ganztägig', toLocaleString(@currentField))"
}

代码说明

  • 当Ganztägig为true时,调用toLocaleDateString仅提取日期,再拼接“ ganztägig”字样;
  • 当Ganztägig为false时,调用toLocaleString返回包含日期和时间的完整格式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 16:27:23