有没有办法可以为自适应卡提供列填充-自适应 MS BOT

2023-12-19

我正在使用自适应卡来使用自适应卡模板包在表格中显示动态内容。

我已经对其进行了自定义,但有一列仍然拒绝到位,该列总是比其他列有更多的内容。因此它超出了行数,因此扩大了表格并使其看起来很难看。[![在此处输入图像描述][1]][1]

async testTableData(context) {
var tablePayLoad = {
  $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "weight": "bolder",
      "size": "Medium",
      "text": "Details",
      "horizontalAlignment": "left",
      "separator": true,
    },
    //Databody
    {
      "type": "ColumnSet",
      "separator": true,
      "bleed": true,
      "spacing": "Padding",
      "columns": [
        //Name
        {
          "type": "Column",
          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "Name",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              "wrap": true,
              "text": "${Name}",
              "size": "small",
              "horizontalAlignment": "center",
            },
          ],
        },
        //Mobile NO
        {
          "type": "Column",
          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "Mobile No",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              "wrap": true,
              "text": "${MobileNo}",
              "size": "small",
              "horizontalAlignment": "center",
            },
          ],
        },
        //Email Address
        {
          "type": "Column",
          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "Email",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              "wrap": true,
              "text": "${Email}",
              "size": "small",
              "horizontalAlignment": "center",
            },
          ],
        },
        //DOB
        {
          "type": "Column",
          "separator": true,
          "width": "auto",
          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "D.O.B",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              "wrap": true,
              "text": "${DOB}",
              "size": "small",
              "horizontalAlignment": "center",
            },
          ],
        },

        //House Address
        {
          "type": "Column",
          "separator": true,

          "bleed": true,
          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "Address",
              horizontalAlignment: "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              wrap: true,
              "size": "small",
              "text": "${HouseAddress}",
              horizontalAlignment: "center",
            },
          ],
        },
        //Location
        {
          "type": "Column",
          "separator": true,

          "bleed": true,
          "items": [
            {
              "type": "TextBlock",
              "weight": "bolder",
              "size": "small",
              "text": "Branch",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              "separator": true,
              "wrap": true,
              "size": "small",
              "horizontalAlignment": "center",
              "text": "${Location}",
            },
          ],
        },
      ],
    },

    {
      "type": "TextBlock",
      "weight": "bolder",
      "size": "Medium",
      "text": "Trans.",
      "horizontalAlignment": "left",
      "spacing": "extraLarge",
      "separator": true,
    },

    //Trans.
    {
      "type": "ColumnSet",
      "separator": true,
      "bleed": true,
      "spacing": "Padding",
      "columns": [
        //Amount
        {
          "type": "Column",
          "separator": true,
          "width": "auto",
          "items": [
            {
              "type": "TextBlock",
              "size": "small",
              "weight": "bolder",
              "text": "Amount",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              $data: "${Trans}",
              "separator": true,
              "text": "${Amount}",
              "size": "small",
              "horizontalAlignment": "center",
              "spacing": "ExtraLarge",
            },
          ],
        },
        //Type
        {
          "type": "Column",
          "width": "auto",
          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "size": "small",
              "weight": "bolder",
              "text": "Type",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              $data: "${Trans}",
              "separator": true,
              "text": "${Type}",
              "size": "small",
              "horizontalAlignment": "center",
              "spacing": "ExtraLarge",
            },
          ],
        },
        //Currency
        {
          "type": "Column",
          "width": "auto",
          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "size": "small",
              "weight": "bolder",
              "horizontalAlignment": "center",
              "text": "Currency",
            },
            {
              "type": "TextBlock",
              $data: "${Trans}",
              "separator": true,
              "size": "small",
              "wrap": true,
              "text": "${Currency}",
              "horizontalAlignment": "center",
              "spacing": "ExtraLarge",
            },
          ],
        },
        //Date
        {
          "type": "Column",
          //   "bleed": true,
          //   width: "auto",

          "separator": true,

          "items": [
            {
              "type": "TextBlock",
              "size": "small",
              "text": "Date",
              "weight": "bolder",
              "horizontalAlignment": "center",
              "wrap": true,
            },
            {
              "type": "TextBlock",
              $data: "${Trans}",
              "separator": true,
              "wrap": true,
              "text": "${Date}",
              "horizontalAlignment": "center",
              "size": "small",
              "spacing": "ExtraLarge",
            },
          ],
        },

        //Comment
        {
          "type": "Column",
          //   width: "stretch",
          "separator": true,
          //   "bleed": true,
          "items": [
            {
              "type": "TextBlock",
              "size": "small",
              "weight": "bolder",
              "text": "Comment",
              "horizontalAlignment": "center",
            },
            {
              "type": "TextBlock",
              $data: "${Trans}",
              "separator": true,
              "size": "small",
              "wrap": true,
              "text": "${Comments}",
              "spacing": "ExtraLarge",
              "horizontalAlignment": "center",
            },
          ],
        },
      ],
    },
  ],
};

// Create a Template instance from the table payload
var template = new ACData.Template(tablePayLoad);

// Expand the template with your `$root` data object.
// This binds it to the data and produces the final Adaptive Card payload

var data = [
  {
    Amount: "6000",
    Type: "C",
    Currency: "NGN",
    Date: "2019-07-19T00:00:00Z",
    Comments: "Just a regular comment here",
  },
  {
    Amount: "6000",
    Type: "C",
    Currency: "NGN",
    Date: "2019-07-19T00:00:00Z",
    Comments: "Just another Comment here",
  },
];
var dob = new Date("1990-05-29T00:00:00Z");

var tableCardPayload = template.expand({
  $root: {
    Name: "JOHN DOE",
    MobileNo: "2349082182323",
    Email: "[email protected] /cdn-cgi/l/email-protection",
    DOB: dob.toLocaleDateString(),
    HouseAddress: "16, Lagos Street, Lagos",
    Location: "Universe",
    Trans: data,
  },
});

const cardToLoad = CardFactory.adaptiveCard(tableCardPayload);

await context
  .sendActivity({ attachments: [cardToLoad] })
  .then()
  .catch((err) => {
    console.log(err);
  });

},


我已经验证使用行而不是列可以解决您的问题。这意味着您将拥有许多每列中有一个元素的列集,而不是每列中有多个元素的一个列集。每个列集将充当一行,并且它们将全部堆叠在彼此的顶部。

我已经为您编写了一个将列转换为行的函数。您可以使用此功能,也可以手动更改您的卡。这是代码:

async function sendCard(card) {
    await turnContext.sendActivity(
        MessageFactory.attachment(CardFactory.adaptiveCard(card))
    );
}

function makeRows(columnSet) {
    const rows = [];

    if (columnSet.columns.length) {
        const numRows = columnSet.columns[0].items.length;
        for (let rowIndex = 0; rowIndex < numRows; rowIndex++) {
            const row = Object.assign({}, columnSet);
            row.columns = [];

            for (const column of columnSet.columns) {
                const item = column.items[rowIndex];
                const rowColumn = Object.assign({}, column);
                //item.wrap = true;
                rowColumn.items = [item];
                row.columns.push(rowColumn);
            }

            rows.push(row);
        }
    } else {
        rows.push(columnSet);
    }

    return rows;
}

function replaceColumnsWithRows(body) {
    for (let index = body.length - 1; index > -1; index--) {
        const element = body[index];
        if (element.type == "ColumnSet") {
            const rows = makeRows(element);
            body.splice(index, 1, ...rows);
        }
    }
}

var tablePayLoad = {
    $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
    type: "AdaptiveCard",
    // Your template
};

// Create a Template instance from the table payload
var template = new ACData.Template(tablePayLoad);

// Expand the template with your `$root` data object.
// This binds it to the data and produces the final Adaptive Card payload

var tableCardPayload = template.expand({
    $root: {
        // Your data
    },
});

await sendCard(tableCardPayload);

replaceColumnsWithRows(tableCardPayload.body);

await sendCard(tableCardPayload);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

有没有办法可以为自适应卡提供列填充-自适应 MS BOT 的相关文章

  • 如何检测被覆盖的 CSS 属性?

    I can get all css properties for an element with document stylesheets but some of those are not active because those pro
  • 提升变量有目的吗?

    我最近学习了很多 JavaScript 并且一直在尝试理解提升变量的值 如果有的话 我 现在 明白JS是一个两遍系统 它编译然后执行 另外 我知道 var 关键字 存在 在它声明的词法范围中 因此如果在引擎为其赋值之前调用它 那么它是 未定
  • 循环遍历数组并删除项目,而不中断 for 循环

    我有以下 for 循环 当我使用splice 要删除一个项目 我发现 秒 未定义 我可以检查它是否未定义 但我觉得可能有一种更优雅的方法来做到这一点 我们的愿望是简单地删除一个项目并继续 for i 0 len Auction auctio
  • 通过纯 JavaScript 获取 div 的第 n 个子元素

    我有一个名为 myDiv 的 div 元素 我怎样才能得到 myDiv 的第n个孩子DOM https en wikipedia org wiki Document Object Model操纵 Markup function reveal
  • jQuery UI Datepicker 奇怪的行为

    我在使用 jqueryUI 使用简单的日期选择器时遇到了一个奇怪的问题 我只想显示两个月的日历 包括上个月和当前月份 我使用了这段代码 function picker datepicker numberOfMonths 2 showCurr
  • 需要参数的addEventListener(和removeEventListener)函数

    我需要向 8 个对象 手掌 添加一些侦听器 这些对象是相同的 但行为必须根据它们的位置而改变 我有以下 丑陋的 代码 root palmsStatus B B B B B B B B if root palmsStatus 0 N root
  • “require(...)”是常见的 JavaScript 模式还是库函数?

    我通常发现这是 node js 脚本 模块以及 phantomJS casperJS 等中的第一行 我很好奇 这是否是服务器端 javascript SSJS 的常见模式 类似于 include在 C C 中或import在 Java 中
  • 如何将类型添加到 Vite 库构建中?

    我按照vite文档使用图书馆模式 https vitejs dev guide build html library mode我能够生成一个工作组件库 我创建了该项目vue ts预设 在我的组件中 我定义了道具及其类型 并使用了一些接口 但
  • Pjax动画

    我终于让 pjax 工作了 但我还有另一个问题 如何添加一些 jquery 动画 如淡出 幻灯片旧内容和淡入 幻灯片新内容 默认情况下 pjax 只是更改内容 没有任何好看的效果 任何帮助将非常感激 此致 基本上 你有一堆事件 https
  • 如何在 JavaScript 中将变量的内容写入文件[重复]

    这个问题在这里已经有答案了 可能的重复 firefox 如何启用本地 JavaScript 来读取 写入我的 PC 上的文件 https stackoverflow com questions 2846045 firefox how to
  • 为什么函数声明在不同浏览器中的处理方式不同?

    虽然我在谷歌中找不到对此的引用 但我熟悉这样一个事实 在 javascript 中 全局函数声明在执行任何代码之前都会被解释 换句话说 这工作得很好 f function f 但是 我注意到 chrome 和 firefox 对全局函数声明
  • 如何按 Angular 表中的属性(该属性具有单个 rownspan)进行分组?

    我没有找到这个问题的合适标题 我的问题是 例如 我有一个包含两列的表 列汽车品牌和列汽车型号 我希望表是 like in this picture 换句话说 品牌名称只会出现 1 次 我的输入数组采用以下 json 格式 brand Aud
  • Aurelia 中的角度服务?

    我还没有找到详细说明如何从 Angular 1 x 迁移到 Aurelia 的详细文档 到目前为止 我只看到人们详细介绍了 Angular 的概念directive可以在 Aurelia 中使用重制 customElement 好吧 足够简
  • 如何使用 GreaseMonkey 让浏览器恢复“/”键?

    Lots of web pages seem to use the key for searching I d like to disable that because 100 of the time I want to use to se
  • AngularStrap 工具提示禁用我的自定义指令

    我正在尝试让 bs tooltip AngularStrap 指令与我自己的名为 checkStrength 的自定义指令一起使用 该指令检查密码的强度 单独使用这些指令中的任何一个时 它们都可以正常工作 但不能一起工作 This http
  • 选择单选按钮时隐藏/显示 3 个文本框

    我有 2 个单选按钮 选择一个文本框时 我想显示 3 个文本框 并在选择其他文本框时隐藏它 这是代码 这是我的 2 个单选按钮
  • 将两个数字相加将它们连接起来而不是计算总和

    我将两个数字相加 但没有得到正确的值 例如 做1 2返回 12 而不是 3 我在这段代码中做错了什么 function myFunction var y document getElementById txt1 value var z do
  • 如何使用 javascript 更改文件扩展名

    有谁知道在 Javascript 中更改文件扩展名的简单方法吗 例如 我有一个带有 first docx 的变量 但我需要将其更改为 first html 这将改变字符串包含文件名 let file first docx file file
  • Keycloak-js updateToken(minValidity) 需要澄清

    我在Keycloak js中阅读了很多该方法的示例 但没有对以下方法进行明确的解释 updateToken minValidity number KeycloakPromise
  • Chrome 调试器注入 javascript

    我有这样的好奇心 是否可以以某种方式在我的页面中注入 javascript 并执行它并调试它 正如您在控制台中所做的那样 但在控制台中您无法暂停并观察变量 是否可以调试我通过控制台输入的代码 为什么无法调试通过 XHR 接收的代码 Than

随机推荐

  • Capistrano 目标路径已存在,不是空目录

    在 Ubuntu 14 04 上使用 Capistrano 部署 Rails 应用程序时 出现以下错误 fatal destination path var www APP NAME repo already exists and is n
  • Qt - 有选择地允许单击进入较低的应用程序窗口

    即使在 Qt 应用程序中 是否也可以接收鼠标单击 对其进行评估 并在必要时让它落入 Qt 应用程序窗口下方可能发生的任何内容 注意Qt WA TransparentForMouseEvents在传递点击之前不利于对其进行评估 而且由于点击评
  • Python - 如何将饼图中的 autopct 文本颜色更改为白色?

    pie fbfrac labels fblabel autopct 1 1f pctdistance 0 8 startangle 90 colors fbcolor 我按照我想要的方式显示图表 但如果文本是白色而不是黑色 则文本在图中会更
  • 使用 async 和await 关键字的好处

    我是 C 中异步方法使用的新手 我读过这些关键词async and await通过异步某些方法来帮助使程序更具响应性 我有这个片段 第一种方式 public static void Main Console WriteLine Hello
  • 使用 SVG 作为背景图像

    我似乎无法让它按预期工作 我的页面根据加载的内容更改高度 如果需要滚动 则 svg 似乎不会拉伸 html height 100 background image url http www horizonchampion eu themes
  • 如何通过 iPhone 应用程序向 Facebook 中的某人发送好友请求?

    有没有办法通过iPhone应用程序发送好友请求 如果是 请帮助我 我在网上搜索过但没有得到解决方案 我得到以下代码来发送应用程序请求而不是发送好友请求 NSMutableDictionary variables NSMutableDicti
  • 用java将BitSet写入文件

    我有一个 BitSet 并想将其写入文件 我遇到了一个使用 writeObject 方法使用 ObjectOutputStream 的解决方案 我查看了java API中的ObjectOutputStream 发现你可以写其他东西 byte
  • 横向模式下的标签栏控制器

    我正在开发一个项目 需要在横向模式下使用应用程序 我通过将界面方向设置为横向来对 plist 文件进行更改 我也将 xib 文件中的方向更改为横向 但当应用程序在模拟器中启动时 选项卡栏控制器仍仅以纵向模式显示 任何人都可以帮忙解决这个问题
  • Angular2限制所有路由

    Helloo 我创建了一个守卫 import Injectable from angular core import Router CanActivate from angular router Injectable export clas
  • 尝试在 JavaScript 中使用 Gruber 的“改进的”URL 匹配正则表达式模式时,如何修复“无效组”错误?

    我正在尝试整合约翰 格鲁伯的一种改进的自由 准确的正则表达式模式 用于匹配 URL http daringfireball net 2010 07 improved regex for matching urls进入我的 JavaScrip
  • JS - 动态更改文本字段

    我正在尝试在不提交任何内容的情况下更改一个文本字段中另一个文本字段的值 例子 文本字段 1 输入 你好 文本字段 2 此处也插入了 你好 下面是我的表格
  • 当应用程序位于前台时,如何计算应用程序的使用时间?

    我正在开发一个 Android 应用程序来跟踪每日应用程序的使用情况 这个想法是 用户可以为任何应用程序设置每日时间限制 超过限制后最多 2 分钟内会出现通知 延迟的原因 我使用创建了一个警报系统报警管理器每分钟都会运行一个类求职意向服务这
  • 将库版本设置为稳定时遇到问题

    我创建了一个在另一个应用程序脚本中使用的库 并查看 Google 上的清单文档 它说如果您希望它自动使用最新版本 您可以将 库 部分中的 版本 设置为 稳定 可用版本 dependency libraries version 字符串 脚本使
  • 表单初始加载后会触发什么事件?

    我对可以在加载表单后触发的事件特别感兴趣 这样我就可以在控制器代码中初始化字段等 没有事件 但您可以添加一个initialize方法 该方法由FXMLLoader创建内容并将字段注入到控制器实例后 public MyController F
  • 使用自动布局的 iOS 消息单元格宽度/高度

    The Goal 我正在尝试创造一个动态message使用自动布局的单元格 我尝试过的 在大多数情况下 单元格的定位正确 并且具有以下约束的自动布局 问题 我的第一个问题是消息标签 可复制标签 宽度受到限制 这似乎可以通过使用来解决setP
  • 字符串中的空字符

    考虑这个字符串 var s A 0Z 它的长度为 3 由下式给出s length Using console log你可以看到绳子没有被切断s 1 is and s charCodeAt 1 is 0 当你在 Firefox 中提醒它时 你
  • Java - 为什么 str.substring(str.length()) 是可接受的代码行? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 长话短说 为什么Java不会为这行代码抛出IndexOutOfBoundsException str substring str length
  • 只是想知道 spring mvc 与 django 之间的区别[关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • 如何在scala中将元组列表转换为数据帧

    我有一个字符串元组列表 List String String String 如何使用 Scala 将其转换为数据帧 你创建一个SparkSession 从 Spark 2 0 0 开始 或SQLContext 然后你可以使用隐式toDF S
  • 有没有办法可以为自适应卡提供列填充-自适应 MS BOT

    我正在使用自适应卡来使用自适应卡模板包在表格中显示动态内容 我已经对其进行了自定义 但有一列仍然拒绝到位 该列总是比其他列有更多的内容 因此它超出了行数 因此扩大了表格并使其看起来很难看 在此处输入图像描述 1 1 async testTa