2017-10-10 72 views
0

我有一个alpaca架构与数组conditional dependencies。数组中的每个值都有一个已知的前缀。可以使用一个函数/条件来检查特定字段中的值,以确定该值是否具有已知的前缀,并导致依赖字段显示,而不是使用数组?如何让alpaca条件依赖使用函数而不是数组?

此问题(conditionally require a field)与我所面临的问题(如何获取和检查函数中某个字段的值)有关。

注意:一个网站可能被归类为多个类型,因此该值为TypePrefix0

这是有问题的代码,因为它目前为:

"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 
     } 
    } 
    } 
} 

回答

0

但不是用一个optiontree控制,将它分成3个select控件。 (第一个是站点类型,另外两个是每个特定类型的站点)。使第二个和第三个选择取决于第一个选择的特定值。这样,您就可以避免在第二个和第三个选择控件的值中使用前缀。