简体   繁体   English

如何使用fabric js创建类似结构的html表?

[英]How to Create html table like structure using fabric js?

vertablo 架构构建器图像

I am trying to build schema builder similar to vertabelo.我正在尝试构建类似于 vertabelo 的模式构建器。 I'm using fabric.js for interactions.我正在使用 fabric.js 进行交互。 How can i create html table like structure where i can add columns and their types as shown in the image.我如何创建类似结构的 html 表,我可以在其中添加列及其类型,如图所示。

Use Html Table inside svg as shown below and convert it into image and use it as fabric object如下所示在 svg 中使用 Html Table 并将其转换为图像并将其用作结构对象

var svgData = '<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200">' +
           '<foreignObject width="100%" height="100%">' +
           '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:30px">' +
             '<table border="1"><thead><tr><td>Title</td></tr></thead><tbody><tr><td>Id</td><td>char</td></tr></tbody></table>' + 
           '</div>' +
           '</foreignObject>' +
           '</svg>';

    // creating image from svg
    const dataUri = `data:image/svg+xml;base64,${window.btoa(svgData)}`;
    const img = new Image();
    img.onload = () => {
        var imgInstance = new fabric.Image(img, {
            left: 0,
            top: 0,
            width: 300,  
            height: 200,  
        });

        canvas.add(imgInstance);
        canvas.renderAll();
    };
    img.src = dataUri;

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

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