如何使羊驼条件依赖使用函数而不是数组?

时间:2017-10-10 09:26:49

标签: dependencies conditional-statements alpacajs

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

这个问题(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
      }
    }
  }
}

1 个答案:

答案 0 :(得分:0)

不是使用optiontree控件,而是将其拆分为三个select控件。 (第一个是站点类型。另外两个是特定类型的每个站点。)使第二个和第三个选择取决于第一个的特定值。这样,您就可以在第二个和第三个选择控件的值中取消前缀。