简体   繁体   English

羊驼-当架构对象是数组类型时,如何设置布局模板?

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

相关问题 在羊驼 object 上添加数组类型和 select 类型 - Adding array type and select type on alpaca object 如何在Mongoose中将架构属性设置为SubDocument类型? - How do you set a schema property to be of type SubDocument in Mongoose? 像猫鼬模式设计一样,如何在javascript对象中设置属性的类型? - How to set type of a property in javascript object, like mongoose schema design do.? 您如何编写一个自定义 object,其中包含另一个类型的自定义对象数组以在 javascript 中存储? - How do you write a custom object containing an array of custom objects of another type to firestore in javascript? 如何格式化 json 参数 object 以便它在模板中正确调用? - how do you format a json parameter object such that it calls correctly in a template? Javascript:创建对象时,如何设置myObject.name之类的内容? - Javascript: when creating an object, how do you set something like myObject.name? 在带有羊驼毛的阵列中使用颜色选择器? - Using a colorpicker in an array with Alpaca? 如何将对象数组转换为 object 的 object - How do you convert an array of objects into an object of object 你如何检查对象数组的 object 中是否存在值? - How do you check if value exist in object of object's array? 如何访问JavaScript数组中的基础对象数组? - How do you access base object Array in a JavaScript Array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM