我正在尝试在自适应卡中创建自定义操作,但无法创建它。有谁能帮帮我吗?
卡片数据
{
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Custom"
}
],
"actions": [
{
"type": "Action.Alert",
"title": "Click me",
"text": "Hello world!"
}
]
}TypeScript文件-新创建的action.ts
import * as AC from "adaptivecards";
export class AlertAction extends AC.Action {
static readonly JsonTypeName = "Action.Alert";
//#region Schema
static readonly textProperty = new AC.StringProperty(AC.Versions.v1_0, "text", true);
@AC.property(AlertAction.textProperty)
text?: string;
//#endregion
getJsonTypeName(): string {
return AlertAction.JsonTypeName;
}
execute() {
alert(this.text);
}
}根据这个链接https://docs.microsoft.com/en-us/adaptive-cards/sdk/rendering-cards/javascript/extensibility,我不知道在哪里添加这行代码
AC.GlobalRegistry.actions.register(AlertAction.JsonTypeName,AlertAction);
这是用于呈现卡片的代码
var jsonTemplate = "some data",
var jsonDate = "some data"
var template = new ACData.Template(jsonTemplate);
var cardPayload = template.expand({
$root: jsonData
});
var adaptiveCard = new AdaptiveCards.AdaptiveCard();
adaptiveCard.onExecuteAction = function(action) {
alert("Ow!");
}
adaptiveCard.parse(cardPayload);
let renderedCard = adaptiveCard.render();
document.body.appendChild(renderedCard);发布于 2021-01-08 21:37:13
我试着像这样添加GlobalRegistry
import {AlertAction} from '../action' // Action file is a TS file
var adaptiveCard = new AdaptiveCards.AdaptiveCard();
adaptiveCard.onExecuteAction = function(action) {
alert("Ow!");
}
adaptiveCard.GlobalRegistry.actions.register(AlertAction.JsonTypeName, AlertAction)我收到类似"ReferenceError:在初始化前无法访问'AlertAction‘“这样的错误
https://stackoverflow.com/questions/65597398
复制相似问题