[英]How do I make alpaca conditional dependencies use a function instead of an array?
I have an alpaca schema with an array of conditional dependencies . 我有一个带有条件依赖项数组的羊驼模式。 Each value in the array has a known prefix.
数组中的每个值都有一个已知的前缀。 Instead of using an array, is it possible to use a function/conditional that checks a value in a certain field to determine if that value has the known prefix and results in the dependent field being shown?
代替使用数组,是否可以使用检查特定字段中的值以确定该值是否具有已知前缀并导致显示依赖字段的函数/条件?
This question ( conditionally require a field ) is related to the problem I'm facing (how to get and check the value of a field in a function). 这个问题( 有条件地需要一个字段 )与我面临的问题(如何获取和检查函数中字段的值)有关。
Note : One site may be categorised in more than one type, hence the TypePrefix0
on the value. 注意 :一个站点可能分类为不止一种类型,因此该
TypePrefix0
上为TypePrefix0
。
This is the code in question, as it currently stands: 这是当前要讨论的代码:
"schema": {
"properties": {
"tpl": { "type":"string" },
"site": { // optionTree
"type":"string",
"title":"Site",
"required": true
},
"sourceType": {
"type":"string",
"title":"Source Type",
"enum":['area','group'],
},
"dataType": {
"type":"string",
"title":"Data Type",
"enum":['people','vehicles', '*']
},
},
"dependencies": {
"dataType": ["sourceType", "site"]
}
},
"options": {
"fields: { // reduced to relevant parts
"dataType": {
"dependencies: {
"sourceType": "group",
// site values shown here are not actual values used in production
"site": ["TypePrefix0.site0", "TypePrefix0.site1", "TypePrefix0.site2", /*...*/]
// how do/can I replace the array with a function/condition:
// (site.value.startsWith("TypePrefix0.")) : true
}
}
}
}
Rather than use an optiontree
control, split it into three select
controls. 与其使用
optiontree
控件, optiontree
将其分为三个select
控件。 (The first one is the site type. The other two are each sites of a specific type.) Make the second and third selects depend on specific values of the first one. (第一个是站点类型。其他两个都是特定类型的站点。)根据第一个和第二个的特定值进行第二和第三选择。 That way, you do away with prefixes in the values of the second and third select controls.
这样,您就不必在第二个和第三个选择控件的值中使用前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.