2017-10-10 74 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控件。 (第一個是站點類型,另外兩個是每個特定類型的站點)。使第二個和第三個選擇取決於第一個選擇的特定值。這樣,您就可以避免在第二個和第三個選擇控件的值中使用前綴。