繁体   English   中英

Formio.js 从构建器方法获取 JSON 文本

[英]Formio.js get JSON text from builder method

我在 github 上阅读了有关 formio.js 的文档。 但是我看不到如何在构建表单后获取 json 文本。

这是我的代码:

<div id='builder'></div>
<script type='text/javascript'>
    var builder = Formio.builder(document.getElementById('builder'), {}, {});

    builder.then(function(form){
        form.on("change", function(e){
             console.log("Something changed on the form builder");
        });
    });
</script>

现在我想将表单的 json 模式存储在数据库中。

我知道这已经回答了,但是对于那些仍然想使用Formio.builder而不是new Formio.FormBuilder你可以试试这个:

Formio.builder(document.getElementById('builder'), {}).then(function(form){
  form.on("change", function(e){
    console.log(form.schema);
  });
});

尝试类似:

...
form.on("change", function(e){
    console.log("Something changed on the form builder");
    var jsonSchema = JSON.stringify(form.submission, null, 4);
    console.log(jsonSchema); // this is the json schema of form components
});
...

或者您可以尝试使用builder.instance.schema ,因为...

form.on("change", function(e){
    console.log("Something changed on the form builder");
    var jsonSchema = JSON.stringify(builder.instance.schema, null, 4);
    console.log(jsonSchema);
});
...

暂无
暂无

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

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