You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Survey Creator功能咨询:添加Import Schema按钮及模板库表单创建

Survey Creator 功能配置问题解答

一、模板库功能是否内置?如何启用?

模板库是Survey Creator的内置功能,你的当前配置未开启该功能,只需在creatorOptions中添加showTemplateTab: true参数即可启用。开启后界面会新增「模板」标签页,用户可直接从内置模板库选择模板快速创建问卷。

修改后的配置示例:

const creatorOptions = {
    showLogicTab: true,
    showSidebar: true,
    showThemeTab: true,
    showPreviewTab: false,
    showPagesInPreviewTab: true,
    showSimulatorInPreviewTab: true,
    showSurveyTitle: true,
    showJSONEditorTab: false,
    showHeaderInEmptySurvey: true,
    showTitlesInExpressions: true,
    allowChangeThemeInPreview: true,
    allowModifyPages: true,
    themeForPreview: "modern",
    designerHeight: "",
    isAutoSave: true,
    showTemplateTab: true // 新增:启用模板库标签页
};

二、如何添加「Import Schema」按钮?

默认工具栏无此按钮,可通过Survey Creator的API手动添加自定义按钮,并实现导入JSON Schema的逻辑,示例代码如下:

// 初始化Survey Creator实例
const creator = new SurveyCreator.SurveyCreator(creatorOptions);

// 向工具栏添加「Import Schema」按钮
creator.toolbar.addItem({
    id: "import-schema",
    title: "Import Schema",
    action: () => {
        // 创建文件选择控件
        const input = document.createElement('input');
        input.type = 'file';
        input.accept = '.json';
        
        input.onchange = (e) => {
            const file = e.target.files[0];
            if (!file) return;
            
            const reader = new FileReader();
            reader.onload = (event) => {
                try {
                    const schema = JSON.parse(event.target.result);
                    // 将导入的Schema加载到Creator
                    creator.JSON = schema;
                } catch (err) {
                    alert('导入失败:JSON格式错误');
                }
            };
            reader.readAsText(file);
        };
        
        input.click();
    },
    visible: true
});

这段代码会在工具栏新增「Import Schema」按钮,点击后弹出文件选择框,选择JSON格式的Schema文件即可将其加载到Survey Creator中。

内容的提问来源于stack exchange,提问作者John Holliday

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:12:42