You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术咨询:如何修改表格数据,将内容替换为<td>左侧信息

实现表格左侧数据动态生成的方案

我来帮你梳理下怎么修改数据,让tableData对应表格<td>左侧的信息:

步骤1:重构tableData的初始化与填充

你现在的tableData是硬编码的固定值,我们改成通过遍历apiInstanceList动态生成,确保每个元素对应表格左侧的目标信息:

// 初始化空数组,替代原来的硬编码内容
var tableData = [];

// 遍历apiInstanceList,逐个填充左侧信息
<g:each in="${apiInstanceList}" var="apiInstance">
    // 替换成你实际需要展示在<td>左侧的字段名,比如apiInstance.airlineName/legName等
    var leftSideInfo = "${apiInstance.yourTargetLeftField}" || null;
    // 保持原有的二维数组格式,将每个左侧信息包装成数组push进去
    tableData.push([leftSideInfo]);
</g:each>

// 后续原有代码保持不变
var cheapestByAirlineByLeg_data1 = [];
var cheapestByAirlineByLeg_data2 = [];
var cheapestByAirlineByLegChart = anychart.column();

<g:each in="${apiInstanceList}" var="apiInstance">
    <g:each in="${apiInstance.cheapestByAirlineByLeg...

关键细节说明

  • 把yourTargetLeftField替换成你业务中实际对应表格左侧的字段名,比如航空公司名称、航段标识等,确保和你要展示的<td>左侧内容匹配。
  • 用|| null处理字段为空的场景,和你原有代码里的null格式保持一致,避免空字符串/undefined破坏表格结构。
  • 遍历逻辑和你后续处理图表数据的循环保持一致,保证数据的对应性。

如果你的左侧信息需要按索引区分(比如第一段、第二段航段的不同标签),可以加索引判断精准控制:

var tableData = [];
<g:each in="${apiInstanceList}" var="apiInstance" status="index">
    var leftSideInfo;
    if (index === 0) {
        leftSideInfo = "${apiInstance.serverName}" || null;
    } else if (index === 1) {
        leftSideInfo = "${apiInstance.serverName2}" || null;
    } else {
        // 处理更多条目的默认值
        leftSideInfo = null;
    }
    tableData.push([leftSideInfo]);
</g:each>

这样就能完美实现把表格<td>左侧的信息动态填充到tableData里了。

内容的提问来源于stack exchange,提问作者Elvis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 06:29:04