【问题标题】:Sharepoint Online - JSON column formattingSharepoint Online - JSON 列格式
【发布时间】:2019-10-24 12:59:42
【问题描述】:

我有以下由 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.LookupValuehttps://github.com/SharePoint/sp-dev-docs/blob/master/docs/declarative-customization/column-formatting.md中所述

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

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

【问题讨论】:

    标签: json sharepoint conditional-formatting


    【解决方案1】:

    首先,你需要使用@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)"
        ]
      }
    }
    

    【讨论】:

    • Michael,请看一下图片,告诉我有什么问题。
    • 我认为您在查找列设置中使用“添加列以显示这些附加字段中的每一个”。对于这些列,只需使用 @currentField 即可。
    • 工作得很好。谢谢。
    猜你喜欢
    • 2020-03-23
    • 2020-11-24
    • 2020-04-11
    • 2018-04-18
    • 1970-01-01
    • 2021-04-01
    • 2020-12-27
    • 2017-07-06
    • 2020-04-12
    相关资源
    最近更新 更多