简体   繁体   English

用变量填充 alpaca 属性

[英]Fill alpaca properties with a variable

I need to assemble a form dynamically using Alpaca Forms.我需要使用 Alpaca Forms 动态组装表格。 I have the code below:我有以下代码:

$("#form").alpaca({        
    "schema": {            
        "type":"object",
        "properties": {                
            "email": {
                "type":"string",
                "title":"E-mail",
                "required":true
            },
            "mensagem": {
                "type":"string",
                "title":"Mensagem",
                "required":true
            }                                        
        }
    }
});

And it needs to be filled in using variables for it to be generic, because the amount of fields that the form will have will always vary.并且需要使用变量来填充它以使其具有通用性,因为表单将具有的字段数量总是会有所不同。 Ex: sometimes in addition to the "email", "mensagem" properties, I will have the "assunto", "remetente", "destinatario" properties例如:有时除了“email”、“mensagem”属性外,我还会有“assunto”、“remetente”、“destinatario”属性

it would need to look something like this:它需要看起来像这样:

$("#form").alpaca({
    "schema" : { schemaVariable }        
});

What you want to achieve is possible, you just need to remove the braces from your variable and use proper JSON object declaration.您想要实现的目标是可能的,您只需从变量中删除大括号并使用正确的 JSON object 声明。

"schema" : schemaVariable

here's a working fiddle for this.这是一个可行的小提琴 Tell me if you need something else.告诉我你是否需要别的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM