Javascript 在Handsontable中使用Handsontable,如何仅从一列返回值?
我正在尝试在一个Handsontable网格中使用“Handsontable”编辑器。我希望用户能够从“下拉”类型菜单中进行选择,但要显示多列相关数据(例如,用户正在选择ID号,我希望能够显示相关的姓名和年龄)。 我有这个工作,但用户可以点击弹出编辑器中的/any/cell,它将返回该单元格中的任何内容。在“ID”单元格中,它工作得很好,但是当我只需要ID列中的值时,我可以很容易地得到返回的“Name”或“Age” 关于如何将返回值强制为/仅为/来自一列,您有什么想法吗 这是我正在做的一个很好的例子(来自热帮助)。在这里,它的工作原理和我的一样。当您单击“Car”字段时,您可以选择“Germany”,而我实际上只需要第一列中的值 想法?您可以向HOT-in-HOT添加一个getValue()方法,如下所示Javascript 在Handsontable中使用Handsontable,如何仅从一列返回值?,javascript,handsontable,Javascript,Handsontable,我正在尝试在一个Handsontable网格中使用“Handsontable”编辑器。我希望用户能够从“下拉”类型菜单中进行选择,但要显示多列相关数据(例如,用户正在选择ID号,我希望能够显示相关的姓名和年龄)。 我有这个工作,但用户可以点击弹出编辑器中的/any/cell,它将返回该单元格中的任何内容。在“ID”单元格中,它工作得很好,但是当我只需要ID列中的值时,我可以很容易地得到返回的“Name”或“Age” 关于如何将返回值强制为/仅为/来自一列,您有什么想法吗 这是我正在做的一个很好
document.addEventListener("DOMContentLoaded", function() {
function getCarData() {
return [
["Nissan", 2013, "black", "black"],
["Nissan", 2014, "blue", "blue"],
["Chrysler", 2015, "yellow", "black"],
["Volvo", 2016, "white", "gray"]
];
}
var
carData = getCarData(),
container = document.getElementById('example1'),
manufacturerData,
colors,
color,
colorData = [],
hot;
manufacturerData = [
{name: 'BMW', country: 'Germany', owner: 'Bayerische Motoren Werke AG'},
{name: 'Chrysler', country: 'USA', owner: 'Chrysler Group LLC'},
{name: 'Nissan', country: 'Japan', owner: 'Nissan Motor Company Ltd'},
{name: 'Suzuki', country: 'Japan', owner: 'Suzuki Motor Corporation'},
{name: 'Toyota', country: 'Japan', owner: 'Toyota Motor Corporation'},
{name: 'Volvo', country: 'Sweden', owner: 'Zhejiang Geely Holding Group'}
];
colors = ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white'];
while (color = colors.shift()) {
colorData.push([
[color]
]);
}
hot = new Handsontable(container, {
data: carData,
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{
type: 'handsontable',
handsontable: {
colHeaders: ['Marque', 'Country', 'Parent company'],
data: manufacturerData,
getValue: function() {
var selection = this.getSelected();
// Get always manufacture name of clicked row
return this.getSourceDataAtRow(selection[0]).name;
}
}
},
{type: 'numeric'},
{
type: 'handsontable',
handsontable: {
colHeaders: false,
data: colorData
}
},
{
type: 'handsontable',
handsontable: {
colHeaders: false,
data: colorData
}
}
],
});
});
您可以向HOT-in-HOT添加getValue()方法,如下所示
document.addEventListener("DOMContentLoaded", function() {
function getCarData() {
return [
["Nissan", 2013, "black", "black"],
["Nissan", 2014, "blue", "blue"],
["Chrysler", 2015, "yellow", "black"],
["Volvo", 2016, "white", "gray"]
];
}
var
carData = getCarData(),
container = document.getElementById('example1'),
manufacturerData,
colors,
color,
colorData = [],
hot;
manufacturerData = [
{name: 'BMW', country: 'Germany', owner: 'Bayerische Motoren Werke AG'},
{name: 'Chrysler', country: 'USA', owner: 'Chrysler Group LLC'},
{name: 'Nissan', country: 'Japan', owner: 'Nissan Motor Company Ltd'},
{name: 'Suzuki', country: 'Japan', owner: 'Suzuki Motor Corporation'},
{name: 'Toyota', country: 'Japan', owner: 'Toyota Motor Corporation'},
{name: 'Volvo', country: 'Sweden', owner: 'Zhejiang Geely Holding Group'}
];
colors = ['yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white'];
while (color = colors.shift()) {
colorData.push([
[color]
]);
}
hot = new Handsontable(container, {
data: carData,
colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
columns: [
{
type: 'handsontable',
handsontable: {
colHeaders: ['Marque', 'Country', 'Parent company'],
data: manufacturerData,
getValue: function() {
var selection = this.getSelected();
// Get always manufacture name of clicked row
return this.getSourceDataAtRow(selection[0]).name;
}
}
},
{type: 'numeric'},
{
type: 'handsontable',
handsontable: {
colHeaders: false,
data: colorData
}
},
{
type: 'handsontable',
handsontable: {
colHeaders: false,
data: colorData
}
}
],
});
});