Sharepoint Online - JSON 列格式

Sharepoint Online - JSON column formatting

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)"
    ]
  }
}

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

中提到的新查找列中

结果只显示“:”。我需要做什么才能让它发挥作用?

此致, 埃里奥·费尔南德斯

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

如果父列表中的字段类型是Number,需要将代码改成这样:

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