【问题标题】:Using MermaidJS in a Cognos Analytics 11 report在 Cognos Analytics 11 报告中使用 MermaidJS
【发布时间】:2020-08-27 18:07:17
【问题描述】:

我正在尝试使用 MermaidJS 在我的 Cognos 11 报告中构建动态甘特图,但它一直返回错误:“Uncaught ReferenceError: mermaidAPI is not defined” 浏览器似乎找不到我对Mermaid 库,但除了通过 javascript 将其添加到标头之外,我不知道如何引用它。

我在引用浏览器不喜欢的美人鱼库时做错了什么?我的JS模块如下:

define( ['jquery'], function($) {

    $('head').append('<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>');
    console.log('appended to head');

    $(document).ready(function() {
        console.log('document load');
        mermaid.initialize({startOnLoad:false});
    });

    function ListToGantt() {
    };

    ListToGantt.prototype.draw = function( oControlHost ) {
        console.log( "PageModule.draw" );

        var oConfig = oControlHost.configuration;
        var table = oControlHost.page.getControlByName(oConfig.name);

        var el = oControlHost.container;
        el.innerHTML +=
            '<div id="mermaidContainer" class="mermaid">' +
            'gantt' +
            '   title EDW Daily Build Gantt Diagram' +
            '   dateFormat  MMM DD YYYY hh:mm:ss A' +
            '   axisFormat  %H:%M %p' +
            '   section 30 Day Avg' +
            '   A task           :a1, Jan 01 2014 01:00:30 am, 30m' +
            '   Another task     :after a1, 20m' +
            '   section Latest Build' +
            '   Task in sec      :Jan 01 2014 01:01:30 am, 12m' +
            '   another task      : 24m' +
            '</div>';

        ///Start of method      
        var tableArr = [];
        // LOOP THROUGH EACH ROW OF THE TABLE AFTER HEADER.
        for (var i = 0; i < table.element.rows.length; i++) {

            // GET THE CELLS COLLECTION OF THE CURRENT ROW.
            var tableRows = table.element.rows[i];
            var tempArray = [];
            // LOOP THROUGH EACH CELL OF THE CURENT ROW TO READ CELL VALUES.
            for (var j = 0; j < tableRows.cells.length; j++) {
                tempArray[j] = tableRows.cells[j].lastChild.innerText;
                //info.innerHTML = info.innerHTML + ' ' + tableRows.item(j).innerHTML;
            }
            tableArr[i] = tempArray;
        }
        console.log(tableArr);
        ///End of method;

    };

    return ListToGantt;
});

【问题讨论】:

    标签: javascript mermaid cognos-11


    【解决方案1】:

    尝试改变这一行

    $('head').append('<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>');
        console.log('appended to head');
    
        $(document).ready(function() {
            console.log('document load');
            mermaid.initialize({startOnLoad:false});
        });
    

    到这里

    $.getScript( "https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js", function( data, textStatus, jqxhr ) {
      console.log( "Load was performed." );
       mermaid.initialize({startOnLoad:false});
    });
    

    【讨论】:

    • 不幸的是,我仍然遇到同样的错误。未捕获的 ReferenceError:未定义美人鱼。
    • 进行此更改后,我查看了控制台,但收到了此警告。与 jsdelivr.net 的跨站点资源关联的 cookie 设置为没有 SameSite 属性。未来版本的 Chrome 将仅通过设置为 SameSite=NoneSecure 的跨站点请求传递 cookie。您可以在开发人员工具中的 Application>Storage>Cookies 下查看 cookie,并在 chromestatus.com/feature/5088147346030592chromestatus.com/feature/5633521622188032 查看更多详细信息。
    • 请您对此错误提出新问题。或者您可以搜索解决方案stackoverflow.com/a/58238399/8235983
    • 我会的,但这只是一个警告,并不能解决我原来关于美人鱼无法加载的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多