使用JSON的SharePoint列格式-RAG状态灯带有文本,如何使其正确对齐?

时间:2019-03-06 16:54:54

标签: json sharepoint

我几乎可以正常工作了,但是我只需要一些有关列格式的帮助。我有一个带有文本列的SharePoint列表,在此列中输入的数据是版本号。 JSON根据版本号创建红色/琥珀色/绿色圆圈,即小于6.4 =红色,小于6.4-6.9 =琥珀色和7+ =绿色。我还保留了文本值,以便将其显示在圆圈中,如您在此处看到的。 SharePoint RAG column

我遇到的问题是我无法使圆或文本居中于列的中心,正如您从下面的代码中看到的那样,我正在使用填充作弊,这使圆位于我想要的位置,但文本仍然存在卡在列的左侧。如您所知,我的JSON有点麻木,所以将不胜感激地收到任何帮助。

{
  "elmType": "div",
  "txtContent": "@currentField",
  "attributes": {},
  "style": {
    "position": "absolute",
    "left": "30%",
    "top": "15%",
    "color": "black",
    "width": "40px",
    "height": "35px",
    "border-radius": "100%",
    "background-color": {
      "operator": "?",
      "operands": [
        {
          "operator": ">",
          "operands": [
            "[$Software_x0020_version]",
            "6.9.9"
          ]
        },
        "#00b300",
        {
          "operator": "?",
          "operands": [
            {
              "operator": "<",
              "operands": [
                "[$Software_x0020_version]",
                "6.3.9"
              ]
            },
            "#ec1313",
            "#ffcc00"
          ]
        }
      ]
    }
  },
  "children": []
}

1 个答案:

答案 0 :(得分:0)

希望这对您有帮助。 enter image description here

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomQuestionGentrator : MonoBehaviour {

    List<int> All_possible_values_of_b = new List<int>();  //List to store all possible value that b can hold;

    void Start ()
    {
        int minRange = 1;
        int MaxRange = 11;

        for (int  i = minRange; i <= MaxRange; i++)    //inserting all possible value of b in list
        {
            All_possible_values_of_b.Add(i);
        }
    }

    void Update ()
    {
        if(Input.GetKeyDown("a"))           //call GenrateNewRandomQuestion when user press correect answer button;
        {
            GenrateNewRandomQuestion();
        }
    }

    void GenrateNewRandomQuestion()
    {
        int a = Random.RandomRange(1, 11);      //a can remain random;

        if(All_possible_values_of_b.Count <= 0)     // changing range when all values of b has been used;
        {
            setnewrange();
        }

        int UsedValueOf_b_InList = Random.Range(0, All_possible_values_of_b.Count);    //accessing remaining values of b in list;

        int b = All_possible_values_of_b[UsedValueOf_b_InList];         //b = some value in list;

        All_possible_values_of_b.RemoveAt(UsedValueOf_b_InList);     //dropping the value of b that is used 

        Debug.Log(a + "x" + b);
    }

    void setnewrange()          //setting new range
    {
        int minRange = 12;
        int MaxRange = 30;
        for (int i = minRange; i <= MaxRange; i++)
        {
            All_possible_values_of_b.Add(i);
        }
    }
}

更新:

更新格式:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "txtContent": "@currentField",
      "attributes": {},
      "style": {
        "position": "absolute",
        "left": "30%",
        "top": "15%",
        "color": "black",
        "text-align": "center",
        "width": "40px",
        "height": "25px",
        "border-radius": "100%",
        "background-color": {
          "operator": "?",
          "operands": [
            {
              "operator": ">",
              "operands": [
                "[$Software_x0020_version]",
                "6.9.9"
              ]
            },
            "#00b300",
            {
              "operator": "?",
              "operands": [
                {
                  "operator": "<",
                  "operands": [
                    "[$Software_x0020_version]",
                    "6.3.9"
                  ]
                },
                "#ec1313",
                "#ffcc00"
              ]
            }
          ]
        }
      }
    }
  ]
}

enter image description here