如何在 App Maker 中绑定下拉菜单和复选框?
How to do binding for drop down and checkbox in App Maker?
来自我的表格截图:
- 如果选项未在下拉列表中列出,如何从下拉列表选项绑定到合同类型,或者如果用户在其旁边的标签中键入输入?
- 复选框选项如何绑定?
对于 Dropdown-Input
组合,我会使用两个模型字段:ContractType
和 CustomContractType
。对于 ContractType
,我会在高级字段设置中指定 possibleValues
(类型一、类型二、类型三,...,其他)并将它们绑定到 Dropdown
的选项:
@models.ModelName.fields.ContractType.possibleValues
并将值绑定到 ContractType
字段:
@datasource.item.ContractType
然后我会绑定 visible
或 enabled
Input
的 属性 到
@datasource.item.ContractType === 'Other'
并将值绑定到 CustomContractType
字段:
@datasource.item.CustomContractType
并在 onBeforeCreate
和 onBeforeSave
模型事件中强制执行此逻辑:
if (record.ContractType !== 'Other' && record.CustomContractType !== null) {
record.CustomContractType = null; // or throw exception...
}
if (record.ContractType === 'Other' && record.CustomContractType === null) {
throw new Error('CustomContractType is required');
}
续订通知(通知?)
如果您只需要 select 一个续订通知,我建议您使用 Radio Group
小部件。否则,您可以继续使用多个复选框并为每个复选框引入多个模型字段 或 使用 Multiselect
select 小部件并尝试将其与字符串模型的字段结合使用split binding transformer (you can find sample in Document Approval 模板,Admin/Settings 页)。
来自我的表格截图:
- 如果选项未在下拉列表中列出,如何从下拉列表选项绑定到合同类型,或者如果用户在其旁边的标签中键入输入?
- 复选框选项如何绑定?
对于 Dropdown-Input
组合,我会使用两个模型字段:ContractType
和 CustomContractType
。对于 ContractType
,我会在高级字段设置中指定 possibleValues
(类型一、类型二、类型三,...,其他)并将它们绑定到 Dropdown
的选项:
@models.ModelName.fields.ContractType.possibleValues
并将值绑定到 ContractType
字段:
@datasource.item.ContractType
然后我会绑定 visible
或 enabled
Input
的 属性 到
@datasource.item.ContractType === 'Other'
并将值绑定到 CustomContractType
字段:
@datasource.item.CustomContractType
并在 onBeforeCreate
和 onBeforeSave
模型事件中强制执行此逻辑:
if (record.ContractType !== 'Other' && record.CustomContractType !== null) {
record.CustomContractType = null; // or throw exception...
}
if (record.ContractType === 'Other' && record.CustomContractType === null) {
throw new Error('CustomContractType is required');
}
续订通知(通知?)
如果您只需要 select 一个续订通知,我建议您使用 Radio Group
小部件。否则,您可以继续使用多个复选框并为每个复选框引入多个模型字段 或 使用 Multiselect
select 小部件并尝试将其与字符串模型的字段结合使用split binding transformer (you can find sample in Document Approval 模板,Admin/Settings 页)。