在 FormioJS Select 中有 data.custom 选项:“有效的 JavaScript 将设置一个值对象,该对象是用于填充选择列表的值。” https://github.com/formio/formio.js/wiki/Select-Component
调用函数有效,设置值无效。我尝试了下面的代码,总是将 [] 作为选择本身的数据:
const getModels = (values, m) => {
console.log(values, m);
values = [{label: ..., value: ...}, {etc}];
return values;
};
表单数据是:
{
type: 'select',
label: 'Manufacturer',
key: 'manufacturer',
placeholder: 'Select your manufacturer',
data: { values: allmanufacturers },
defaultValue: ''
},
{
type: 'select',
label: 'Model',
key: 'model',
placeholder: 'Select your model',
refreshOn: 'manufacturer',
dataSrc: 'custom',
data: { custom: 'getModels(values, data.manufacturer)' },
selectValues: 'Results'
},