[英]Alpaca - How do you set a Layout template when the schema object is an Array type?
Is there a way to set a View template for an array list object inside the schema? 有没有一种方法可以为架构内的数组列表对象设置View模板?
I found the Documentation about the layout, but it does not work in my case, because my schema contains only an array of object with multiple fields inside. 我找到了有关布局的文档 ,但是在我的情况下它不起作用,因为我的架构仅包含内部有多个字段的对象数组。 On page load i don't get any error, and my alpaca object contains the template i added without the records inside of it.
在页面加载时,我没有任何错误,并且我的羊驼对象包含我添加的模板,其中没有记录。
var Schema = { "title": "Lista controlli", "type": "array", "items": { "type": "object", "title": "Controllo Lavorazione", "properties": { "Id": { "title": "Id", "type": "string" }, "Tipo": { "title": "Tipo controllo", "type": "number", "required": true, "enum": [1, 2, 3, 4] }, "Obbligatorio": { "required": true }, "Nome": { "title": "Nome", "type": "string", "required": true }, "Sigla": { "title": "Sigla", "type": "string", "required": true }, "Posizione": { "title": "Posizione", "type": "number" }, "Valore": { "title": "Valore", "type": "number", "required": true }, "UM": { "title": "Unita Misura", "type": "string" }, "TolleranzaMeno": { "title": "Tolleranza (-)", "type": "number", "required": true }, "TolleranzaPiu": { "title": "Tolleranza (+)", "type": "number", "required": true }, "Lettura": { "title": "Valore letto", "type": "string" } } } } var Lavorazioni_Options = { "type": "array", "toolbarSticky": true, "items": { "type": "object", "fields": { "Id": { "hidden": true }, "Tipo": { "type": "select", "sort": function(a, b) { if (a.value > b.value) { return 1; } else if (a.value < b.value) { return -1; } return 0; }, "noneLabel": "-- Seleziona --", "removeDefaultNone": false, "showMessages": false, "optionLabels": ["Numerico", "Testo", "Flag", "Nota"] }, "Obbligatorio": { "rightLabel": "Controllo Obbligatorio", "type": "checkbox" }, "Posizione": { "showMessages": false, "hidden": true }, "Nome": { "showMessages": false }, "Sigla": { "showMessages": false }, "Valore": { "hidden": true }, "TolleranzaPiu": { "hidden": true }, "TolleranzaMeno": { "hidden": true }, "UM": { "hidden": true }, "Lettura": { "hidden": true } } }, "focus": false, "helpers": [], "validate": true, "disabled": false, "showMessages": false, "legendStyle": "button", "hideInitValidationError": true } var LavorazioniEdit_Options = { "type": "array", "toolbarSticky": true, "items": { "type": "object", "fields": { "Id": { "disabled": true }, "Tipo": { "type": "select", "sort": function(a, b) { if (a.value > b.value) { return 1; } else if (a.value < b.value) { return -1; } return 0; }, "noneLabel": "-- Seleziona --", "removeDefaultNone": false, "showMessages": false, "optionLabels": ["Numerico", "Testo", "Flag", "Nota"] }, "Obbligatorio": { "rightLabel": "Controllo Obbligatorio", "type": "checkbox" }, "Posizione": { "showMessages": false, "hidden": true }, "Nome": { "showMessages": false }, "Sigla": { "showMessages": false }, "Valore": { "hidden": true }, "TolleranzaPiu": { "hidden": true }, "TolleranzaMeno": { "hidden": true }, "UM": { "hidden": true }, "Lettura": { "hidden": true } } }, "focus": false, "helpers": [], "validate": true, "disabled": false, "showMessages": false, "legendStyle": "button", "hideInitValidationError": true } var LavorazioniArticoli_Options = { "type": "array", "toolbarSticky": true, "items": { "type": "object", "fields": { "Id": { "hidden": true }, "Tipo": { "type": "select", "disabled": true, "sort": function(a, b) { if (a.value > b.value) { return 1; } else if (a.value < b.value) { return -1; } return 0; }, "noneLabel": "-- Seleziona --", "removeDefaultNone": false, "showMessages": false, "optionLabels": ["Numerico", "Testo", "Flag", "Nota"] }, "Obbligatorio": { "rightLabel": "Controllo Obbligatorio", "disabled": true, "type": "checkbox" }, "Posizione": { "showMessages": false, "hidden": true }, "Nome": { "showMessages": false, "disabled": true }, "Sigla": { "showMessages": false }, "Valore": { "multipleOf": 0.01, "showMessages": false }, "TolleranzaPiu": { "multipleOf": 0.01, "showMessages": false }, "TolleranzaMeno": { "multipleOf": 0.01, "showMessages": false }, "UM": {}, "Lettura": { "hidden": true } } }, "focus": false, "helpers": [], "validate": true, "disabled": false, "showMessages": false, "legendStyle": "button", "hideInitValidationError": true } var lavorazioniView = { "parent": "bootstrap-edit-horizontal", "layout": { "template": "<div class='row'><div class='col-md-6' id='column-1'></div><div class='col-md-6' id='column-2'></div></div>", "bindings": { "Id": "column-1", "Posizione": "column-2", "Tipo": "column-1", "Obbligatorio": "column-2", "Nome": "column-1", "Sigla": "column-2", "Valore": "column-1", "UM": "column-2", "TolleranzaMeno": "column-1", "TolleranzaPiu": "column-2", "Lettura": "column-1" } } } $(function() { $('#jsoneditor').alpaca({ "schema": Schema, "options": Lavorazioni_Options, //"view": lavorazioniView }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.0/handlebars.js"></script> <script src="https://code.cloudcms.com/alpaca/1.5.23/bootstrap/alpaca.min.js"></script> <link href="https://code.cloudcms.com/alpaca/1.5.23/bootstrap/alpaca.min.css" rel="stylesheet" /> <div id="jsoneditor" class="jsoneditor-wrapper"></div>
Thanks in advance 提前致谢
It looks like currently this is not possible. 目前看来这是不可能的。 There is an outstanding issue on the alpaca repo for this.
羊驼回购上有一个未解决的问题。
https://github.com/gitana/alpaca/issues/549 https://github.com/gitana/alpaca/issues/549
"Layout bindings only works for the top level schema elements but not for sub-elements." “布局绑定仅适用于顶层架构元素,而不适用于子元素。”
Sorry if this ruins your day (like it would mine). 抱歉,这会毁了您的一天(就像我的一天一样)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.