在更改为 BoostrapTable X-editable select 框时获取文本而不是值

Getting text instead of value on change to BoostrapTable X-editable select box

我使用 BootstrapTablex-editable 构建了一个 table,其中包含一个 select 联系人框。当用户 select 设置新值时,我会提醒他们 select 编辑的内容。使用 editable-save.bs.table,我能够获得与 selection 选项关联的值,但这对用户来说毫无意义。我想获取与该值关联的联系人姓名。我该怎么做

Fiddle: http://jsfiddle.net/cdvtkndu/

var data = [{"Contact": 3}, {"Contact": 2}];

$(function () {
    $('#table').bootstrapTable({
        columns: [{
            field: 'Contact',
            title: 'Contact',
            editable: {
                type: 'select',
                source: [
                    {value: 4, text: 'Andrew'},
                    {value: 2, text: 'John'},
                    {value: 3, text: 'Liz'}
                ]
            }
        }],
        data: data
    });
});

$('#table').on('editable-save.bs.table', function (e, field, row, old, $el) {
    var new_val = row[field];
    alert(new_val);
});

您可以将源转储到一个数组中,然后遍历它以找到您正在搜索的行:

var data = [{"Contact": 3}, {"Contact": 2}];
var _source = [
                    {value: 4, text: 'Andrew'},
                    {value: 2, text: 'John'},
                    {value: 3, text: 'Liz'}
                ];
$(function () {
    $('#table').bootstrapTable({
        columns: [{
            field: 'Contact',
            title: 'Contact',
            editable: {
                type: 'select',
                source: _source
            }
        }],
        data: data
    });
});
$('#table').on('editable-save.bs.table', function (e, field, row, old, $el) {
    var new_val = row[field];
    var arrayLength = _source.length;
    for (var i = 0; i < arrayLength; i++) {
        if (_source[i].value == new_val) {
                alert(_source[i].text);
          break;
        }
    }    
});

看我更正:http://jsfiddle.net/4qq1yp1y/