首页 > 解决方案 > Sharepoint Online - JSON 列格式

问题描述

我有 Michael Han 给出的以下代码,它工作得很好。它将像“2030”这样的数字格式化为“20:30”

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": {
    "operator": "+",
    "operands": [
      "=substring(toString(@currentField),0,2)",
      ":",
      "=substring(toString(@currentField),2,4)"
    ]
  }
}

我需要将此列用作另一个列表的查找列,因此我粘贴了此代码并在https://github.com/SharePoint/sp-dev-中提到的新查找列中将@currentField替换为@currentField.LookupValue docs/blob/master/docs/declarative-customization/column-formatting.md

结果只是显示“ ”。我必须做些什么才能让它发挥作用?

问候, 埃利奥·费尔南德斯

标签: jsonsharepointconditional-formatting

解决方案


首先,您需要使用@currentField.lookupValue而不是@currentField.LookupValue,lookupValue 的第一个字符应该是小写的。并且代码仅在父列表中的字段是单行文本时才有效。

在此处输入图像描述

如果父列表中的字段类型是数字,则需要将代码更改为:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": {
    "operator": "+",
    "operands": [
      "=substring(toString(@currentField.lookupValue),0,1)",
      "=substring(toString(@currentField.lookupValue),2,3)",
      ":",
      "=substring(toString(@currentField.lookupValue)3,5)"
    ]
  }
}

推荐阅读