问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/59943893/how-do-dynamically-bind-data-to-adaptive-card