Display number in adaptive card

天涯浪子 提交于 2020-07-02 03:09:27

问题


I have the following simple card:

    {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "{data}"
            }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
    }

When I apply the following data to the card (value is number), the text box is empty:

{
"data":11111
}

With text, the I can see the data in the card:

{
"data":"11111"
}

This is not a code issue, this is how it looks in the designer. Am I missing something, is there a type for a text box that lets display numbers or is this by design and I have to change all numeric fields to text?


回答1:


This is a limitation of the preview (known as Type Coercion) that we hope to address before release. As another workaround you can include a space after the binding expression which will force it into a string. See the below example, notice the space after {data}


   {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "{data} "
            }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
    }



回答2:


I'm guessing you're using Adaptive Cards Templating for this. Remember, this is (a) in preview only and (b) just one option for constructing an Adaptive Card. Basically, at the end of the day, the Card is just a string of JSON text so you can create it in 3 main ways:

  1. Using Templates, as you're doing now
  2. Doing string replacement of your own (e.g. var card = '..."text": "##Number##"...' and then card = card.Replace("##Number##", formattedNumberValue)
  3. Using strongly-typed options like the AdaptiveCards Nuget package for C#, for instance

So, I'd suggest, if this is not possible using Templating, to look more at options 2 or 3 above. I described this a bit more here, with some links to C# and Node examples.

Hope that helps



来源:https://stackoverflow.com/questions/59662677/display-number-in-adaptive-card

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!