如何将数据动态绑定到自适应卡? [英] How do dynamically bind data to adaptive card?

查看:95
本文介绍了如何将数据动态绑定到自适应卡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用c#.net创建了一个漫游器.我正在从SharePoint列表中获取数据,它将获取许多行.行数是动态的.当机器人在团队中回答时,我想以表格格式添加数据.我想使用自适应卡以表格格式显示数据,但是如何将数据绑定到自适应卡中,因为行数会根据向机器人提出的问题而变化?如何在c#.net bot代码中将数据动态绑定到cad?

I have created a bot using c#.net. I am fetching data from the SharePoint list and it will fetch a number of rows. The number of rows is dynamic. I want to add data in a Table format when the bot will answer in Teams. I want to use adaptive cards for showing data in a table format, but how do I bind that data in an adaptive card as the number of rows will change according to question asked to bot? How can I bind data to cad dynamically in c#.net bot code?

推荐答案

这根本没有问题,您可以简单地在服务器端(即在您的机器人中)用行数构建自适应卡.可以将自适应卡的JSON构造为字符串(使用stringbuilder),或者在使用C#时,可以使用强类型的AdaptiveCards nuget包,并在C#中完成所有操作,例如:

This is no problem at all, you can simply build up the adaptive cards server-side (i.e. in your bot) with the amount of rows. It's possible to either construct the JSON for the adaptive card as a string (using stringbuilder) or, as you're using C#, you can using the strongly typed AdaptiveCards nuget package and do it all in C#, something like:

            var items = new System.Collections.Generic.List<AdaptiveElement>();
            for (int i = 0; i < whatever.count; i++)
            {
                items.Add(new AdaptiveTextBlock()
                {
                    Text = $"Item {i}",
                });
            }

            card.Body.Add(
                new AdaptiveContainer()
                {
                    Items = items
                }
            );

我在此答案中对此进行了更多讨论:

I discuss this more in this answer: How to convert custom json to adaptive card json format

这篇关于如何将数据动态绑定到自适应卡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆