Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用Handsontable保存下拉选项_Jquery_Json_Ajax_Handsontable - Fatal编程技术网

Jquery 使用Handsontable保存下拉选项

Jquery 使用Handsontable保存下拉选项,jquery,json,ajax,handsontable,Jquery,Json,Ajax,Handsontable,我在Handsontable中的一列上设置了一个ajax调用,以返回存储在数据库中的选项 columns: [ {data: 'firstName'}, {data: 'lastName'}, {data: 'department', type: 'dropdown', strict: false, source: function(query, process){ $.ajax({

我在Handsontable中的一列上设置了一个ajax调用,以返回存储在数据库中的选项

columns: [
    {data: 'firstName'},
    {data: 'lastName'},
    {data: 'department',  
        type: 'dropdown',
        strict: false, 
        source: function(query, process){ 
            $.ajax({
            url: '/getDepartments',
            dataType: 'json',
            success: function (response) {
              var values = [];
              for (i in response) values.push(response[i].name);
              process(values);
            }
        });
    }
我的部门列表填充得很好,但是当我坚持任何更改时,我需要发送部门ID(因为此ID是我用户表中的外键)。我想知道如何用HOT实现这一点——对于这种情况,他们是否提供了将int值绑定到字符串的方法


我还认为我可以将ID存储在一个隐藏的单元格中,但在创建比我需要的更多工作之前,我正在对API进行更多的阅读。典型的解决方案只是将隐藏的单元格作为数据对象的一部分,并通过不在
列中定义来隐藏它。目前还没有其他方法可以使用HOT将ID绑定到一行。

我曾经解决过这个问题

您必须包括repo中提供的.js文件,并定义所需的customDropdownRenderer

function customDropdownRenderer(instance, td, row, col, prop, value, cellProperties)
{
    var selectedId;
    for (var index = 0; index < optionsList.length; index++)
    {
        if (parseInt(value) === optionsList[index].id)
        {
            selectedId = optionsList[index].id;
            value = optionsList[index].text;            
        }
    }
    Handsontable.TextCell.renderer.apply(this, arguments);
    // you can use the selectedId for posting to the DB or server
    $('#selectedId').text(selectedId);
}
函数customDropdownRenderer(实例、td、行、列、属性、值、单元格属性)
{
var-selectedId;
对于(变量索引=0;索引
工作示例如下: