如何制作动态丰富的卡片

时间:2018-06-04 12:58:51

标签: asp.net carousel botframework bots

我正在尝试创建一个丰富的卡片旋转木马。我有一个数组中的数据,我希望根据我的数组大小动态生成一张新卡。

这是我的样本轮播代码,只返回一张卡片。

var attachment = new List<Attachment>()
{ 
    GetRideType(
        lon,
        lat,
        item,
        "MIN FARE: 200/=, MAX PASS: 4",
        "Click on the button to request basic ride type.",
        // imageUrl, 
        new CardAction(ActionTypes.ImBack, "Basic", value: "Basic"),
        new CardAction(ActionTypes.ImBack, "Basic", value: "Basic")
        ),
};

return attachment;

我能否以卡片数量由阵列大小预先确定的方式使其动态化?

1 个答案:

答案 0 :(得分:0)

我假设您想要一个卡片轮播,并假设您将数据数组放在名为dataArray的变量中。只需遍历它并创建附件并将其添加到attachment

示例代码为:

var attachment = new List<Attachment>();
foreach (var data in dataArray)
{
    attachment.Add(
        GetRideType(
            lon,
            lat,
            item,
            "MIN FARE: 200/=, MAX PASS: 4",
            "Click on the button to request basic ride type.",
            // imageUrl, 
            new CardAction(ActionTypes.ImBack, "Basic", value: "Basic"),
            new CardAction(ActionTypes.ImBack, "Basic", value: "Basic")
        )
    )
}