carousel card issue when using with for loop to make it dynamic but it show only last card
var msg = new builder.Message(session) .textFormat(builder.TextFormat.xml) .attachmentLayout(builder.AttachmentLayout.carousel);
msg.attachments(HeroCard);
for(var i = 0; i < jsonObj.d.results.length;i++)
{
new builder.HeroCard(session)
.title(jsonObj.d.results[i].Name1)
.text("<b>%s</b> sot user",jsonObj.d.results[i].Name1)
.images([builder.CardImage.create(session,"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/800px-Seattlenighttimequeenanne.jpg").tap(builder.CardAction.showImage(session,"https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/800px-Seattlenighttimequeenanne.jpg")),
])
.buttons([
builder.CardAction.imBack(session, jsonObj.d.results[0].Name1, "Select")
]);
}
builder.Prompts.choice(session, msg, "select:100|select:101|select:102");
is it possible you're hitting the 5-card limit (on some channels) with this? Try boxing the for loop to a max of 5 and see how you fare as a troubleshooting step.
i am using with limti three also but it is not working
I think you should check this 'jsonObj.d.results.length'. check the value of this is correct or not using console.log.
i also have checked it its less than 5 but it shows last card only
Are you setting the layout property to "carousel"?
yes
hey @subhans3tech you are missing an append step (that's why you only see the last card). according to the AttachmentLayout reference, attachments should be rendered as a list. not sure if it's the most elegant solution, but given a JSON, docs, with schema:
"results": [{
"Name": [{
"text": "...",
"href": "..."
}],
"Category": [{
"text": "..."
}],
"Image": [{
"src": "...",
"alt": "...",
"href": "..."
}],
"Rating": [{
"text": "..."
}],
"Address": [{
"text": "..."
}]
},
...
]
then this should do the trick:
var tmpDeck = [];
docs[0].results.slice(0,3).forEach( (result) => {
var tmpCard = [
new builder.HeroCard(session)
.title(result.Name[0].text)
.subtitle(`${result.Category[0].text}, ${result.Rating[0].text}`)
.text(result.Address[0].text)
.images([
builder.CardImage.create(session, result.Image[0].src)
.tap(builder.CardAction.showImage(session, result.Image[0].src)),
])
.buttons([
builder.CardAction.openUrl(session, result.Image[0].href, "Reviews")
])
];
tmpDeck.push(...tmpCard);
});
var msg = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(tmpDeck);
// Show carousel
session.send(msg);
If this did not solve your issue, please reopen.