我正在使用BOT Framework v 3,我有一个自适应卡,可以从用户那里获取输入,我希望Dropdown中的值是动态的。这是自适应卡设计代码,您可以看到我已经输入了手动选择,而不希望它从数据库中是动态的
var card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock()
{
Color = TextColor.Attention,
Weight = TextWeight.Bolder,
Size = TextSize.Medium,
Text = "Select a title",
},
new ChoiceSet()
{
Id = "title",
Style = ChoiceInputStyle.Compact,
IsRequired = false,
IsMultiSelect = false,
Value = "1",
Choices = new List<Choice>()
{
new Choice()
{
Title = "Swiss cargo",
Value = "Swiss cargo",
},
new Choice()
{
Title = "ticket booking",
Value = "ticket booking",
},
},
},
},
};
答案 0 :(得分:0)
假设您可以将数据放入字符串列表中,则可以使用Linq轻松地动态构建自适应卡。如果要继续使用相同的Adaptive Cards库,则如下所示:
var data = new List<string> { "Swiss cargo", "ticket booking" };
var card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock()
{
Color = TextColor.Attention,
Weight = TextWeight.Bolder,
Size = TextSize.Medium,
Text = "Select a title",
},
new ChoiceSet()
{
Id = "title",
Style = ChoiceInputStyle.Compact,
IsRequired = false,
IsMultiSelect = false,
Value = "1",
Choices = data.Select(item => new Choice { Title = item, Value = item }).ToList(),
},
},
};