提交中的自适应卡片输入值
Adaptive Cards Input Values in Submit
您好,我在网页中使用 Adaptive card SDK,使用这样的示例卡:
var card = {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Present a form and submit it back to the originator"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "What is your first name?"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "What is your last name?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Action.Submit"
}
]};
并使用通常的规则进行渲染。我想通过提交取回输入,所以我尝试了这个
// Set the adaptive card's event handlers. onExecuteAction is invoked
// whenever an action is clicked in the card
adaptiveCard.onExecuteAction = function (action) { console.log(action.toJSON()) }
这给了我:
Object title: "Action.Submit" type: "Action.Submit" __proto__: Object
如何获取提交操作中输入字段的值?
任何意见、建议和答案的 TIA
您可以像这样使用动作对象的data
属性:
adaptiveCard.onExecuteAction = function (action) {
alert(`Hello ${action.data.firstName} ${action.data.lastName}`);
}
这是完整的 jsfiddle。
action 对象 上还有许多其他有趣的属性,但我没有找到好的文档。
但是,自适应卡片可视化器的 source code 包含一些使用示例。
您好,我在网页中使用 Adaptive card SDK,使用这样的示例卡:
var card = {
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Present a form and submit it back to the originator"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "What is your first name?"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "What is your last name?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Action.Submit"
}
]};
并使用通常的规则进行渲染。我想通过提交取回输入,所以我尝试了这个
// Set the adaptive card's event handlers. onExecuteAction is invoked
// whenever an action is clicked in the card
adaptiveCard.onExecuteAction = function (action) { console.log(action.toJSON()) }
这给了我:
Object title: "Action.Submit" type: "Action.Submit" __proto__: Object
如何获取提交操作中输入字段的值?
任何意见、建议和答案的 TIA
您可以像这样使用动作对象的data
属性:
adaptiveCard.onExecuteAction = function (action) {
alert(`Hello ${action.data.firstName} ${action.data.lastName}`);
}
这是完整的 jsfiddle。
action 对象 上还有许多其他有趣的属性,但我没有找到好的文档。 但是,自适应卡片可视化器的 source code 包含一些使用示例。