最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何使用ListStyle.heroCard将自定义数据添加到ChoicePrompt

IT培训 admin 8浏览 0评论

如何使用ListStyle.heroCard将自定义数据添加到ChoicePrompt

我有一个ChoicePrompt,其样式为ListStyle.heroCard,如下所示:

import {ChoicePrompt, ListStyle} from 'botbuilder-dialogs';
import {PromptValidator} from 'botbuilder-dialogs/src/prompts/prompt';
import {FoundChoice} from 'botbuilder-dialogs/src/choices/findChoices';

export class HeroCardChoicePrompt extends ChoicePrompt{
    constructor(dialogId: string, validator?: PromptValidator<FoundChoice>, defaultLocale?: string){
        super(dialogId, validator, defaultLocale)
        this.style = ListStyle.heroCard
    }
}

然后我添加了这个选择对象:

choices.push({
    action: {

        text: 'Lolipop',
        displayText: 'Lolipop',
        channelData: 'Lolipop',

        type: 'postBack',
        title:  'Lolipop',
        value:  'Lolipop',

    },
    value: 'Can you please help me to manage...',
    synonyms: []
},)

当用户单击选项时,如何在代码中获取数据'Lolipop'

[当我在漫游器模拟器中检查客户端接收到的JSON对象时,根本看不到数据'Lolipop'

回答如下:

使用ListStyle.heroCard使提示符使用ChoiceFactory.heroCard生成卡。您可以在source code中看到ChoiceFactory.heroCard不在选择中使用动作,而是仅创建imBack动作:

const buttons: CardAction[] = choices.map(choice => ({
    title: choice.value,
    type: ActionTypes.ImBack,
    value: choice.value
} as CardAction));

如果要在提示中提供自定义操作,则需要创建自己的英雄卡,并将其作为提示选项的prompt字段提供,并使用ListStyle.none。目前尚不清楚您为什么要这样做,因为ChoiceFactory生成的操作将与选择提示中的可用选项匹配,因此不需要该活动具有隐藏值。

如何使用ListStyle.heroCard将自定义数据添加到ChoicePrompt

我有一个ChoicePrompt,其样式为ListStyle.heroCard,如下所示:

import {ChoicePrompt, ListStyle} from 'botbuilder-dialogs';
import {PromptValidator} from 'botbuilder-dialogs/src/prompts/prompt';
import {FoundChoice} from 'botbuilder-dialogs/src/choices/findChoices';

export class HeroCardChoicePrompt extends ChoicePrompt{
    constructor(dialogId: string, validator?: PromptValidator<FoundChoice>, defaultLocale?: string){
        super(dialogId, validator, defaultLocale)
        this.style = ListStyle.heroCard
    }
}

然后我添加了这个选择对象:

choices.push({
    action: {

        text: 'Lolipop',
        displayText: 'Lolipop',
        channelData: 'Lolipop',

        type: 'postBack',
        title:  'Lolipop',
        value:  'Lolipop',

    },
    value: 'Can you please help me to manage...',
    synonyms: []
},)

当用户单击选项时,如何在代码中获取数据'Lolipop'

[当我在漫游器模拟器中检查客户端接收到的JSON对象时,根本看不到数据'Lolipop'

回答如下:

使用ListStyle.heroCard使提示符使用ChoiceFactory.heroCard生成卡。您可以在source code中看到ChoiceFactory.heroCard不在选择中使用动作,而是仅创建imBack动作:

const buttons: CardAction[] = choices.map(choice => ({
    title: choice.value,
    type: ActionTypes.ImBack,
    value: choice.value
} as CardAction));

如果要在提示中提供自定义操作,则需要创建自己的英雄卡,并将其作为提示选项的prompt字段提供,并使用ListStyle.none。目前尚不清楚您为什么要这样做,因为ChoiceFactory生成的操作将与选择提示中的可用选项匹配,因此不需要该活动具有隐藏值。

发布评论

评论列表 (0)

  1. 暂无评论