【问题标题】:Handsontable dropdown source from column property来自列属性的 Handsontable 下拉源
【发布时间】:2017-04-01 18:24:05
【问题描述】:

找不到解决方案,所以也许有人会帮忙。

我有一组类似这样的数据:

    [
        {
        id: 1,
        name: 'Nissan',
        year: 2012,
        chassis_color: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
      },
      {
        id: 2,
        name: 'Chrysler',
        year: 2014,
        chassis_color: ['red', 'orange', 'blue', 'gray', 'black', 'white']
      },
      {
        id: 3,
        name: 'Volvo',
        year: 2015,
        chassis_color: ['white', 'orange', 'blue', 'red']
      }
    ]

所以我不知道如何通过手动输入数组值而不是从它的值填充底盘颜色列下拉列表。

文档中的示例:

columns: [
      {
        type: 'dropdown',
        source: ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white']
      }
]

但我需要这个:

columns: [
          {
            type: 'dropdown',
            source: 'chassis_color' // it should understand that this property is an array and populate source with it
          }
]

以同样的方式工作。

我需要这个,因为我有大量数据,手动设置会很困难。

谢谢。

【问题讨论】:

    标签: javascript handsontable


    【解决方案1】:

    Handsontable 只是尝试将您的数组显示为数据。

    您可以使用单元格属性来更改源值:

    cells: function(row, col, prop) {
        var cellProperties = this;
    
        if (col == 0) {
            cellProperties.type = 'dropdown';
            var val = data[row].chassis_color_source;
    
            if (typeof val != 'undefined') {
                cellProperties.source = val;
            }
        }
    
        return cellProperties;
    }
    

    JSFiddle 中的完整示例。

    【讨论】:

    • 你拯救了我的一天。谢谢!
    猜你喜欢
    • 2015-08-19
    • 2015-10-04
    • 2015-10-19
    • 2018-12-21
    • 1970-01-01
    • 2017-03-25
    • 2022-09-30
    • 1970-01-01
    • 2019-03-31
    相关资源
    最近更新 更多