简体   繁体   English

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

[英]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.

相关问题 如何对外部依赖项使用依赖项注入? - How do I use dependency injection for external dependencies? 如何在IDE中使用Grails依赖项 - How to make use of Grails Dependencies in your IDE 如何使Intellij停止删除Grails内联插件模块依赖项? - How do I make Intellij stop removing Grails inline plugin module dependencies? 如何使Intellij Idea“Spring Dependencies Diagram”仅显示bean的子集? - How do I make Intellij Idea “Spring Dependencies Diagram” to show only a subset of the beans? 如何使用Gemfile在Rails 3应用程序中自动加载gemspec依赖项 - How do I make gemspec dependencies autoload in a Rails 3 app, using a Gemfile 在 Maven 依赖项的上下文中,我如何理解类路径及其对执行的影响? - In the context of Maven dependencies, how do I make sense of classpaths and their effect on execution? 常春藤:如何删除传递依赖? - Ivy: how do I remove transitive dependencies? 如何管理常见的lisp依赖项? - How do I manage common lisp dependencies? 如何安装Perl脚本依赖项? - How do I install Perl script dependencies? 基于函数结果的条件 Gradle 依赖 - Conditional Gradle dependencies based on function result
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM