无法以编程方式关闭格式化文本

Vic*_*tor 6 javascript mxgraph

我试图以编程方式为我的图形中的每个单元格关闭格式化文本,这样我就可以避免mxgraph编辑中的查看器不支持(类似于Draw.io)

这是我的尝试:

graph.stopEditing();
graph.getModel().beginUpdate();

try
{
    var cells = graph.getChildCells(graph.getDefaultParent());
    cells.forEach(function (cell)
    {
        var state = graph.getView().getState(cell);
        if (state == null)
        {
            return;
        }
        if (state.style['html'] != '1') {
            return;
        }

        var label = graph.convertValueToString(state.cell);
        if (mxUtils.getValue(state.style, 'nl2Br', '1') != '0')
        {
            label = label.replace(/\n/g, '').replace(/<br\s*.?>/g, '\n');
        }

        // Removes HTML tags
        var temp = document.createElement('div');
        temp.innerHTML = label;
        label = mxUtils.extractTextWithWhitespace(temp.childNodes);

        graph.cellLabelChanged(state.cell, label);
        graph.setCellStyles('html', null);
    });

    ui.fireEvent(new mxEventObject('styleChanged', 'keys', ['html'],
        'values', ['0'], 'cells', cells));
}
finally
{
    graph.getModel().endUpdate();
}
Run Code Online (Sandbox Code Playgroud)

但它似乎不起作用(即如果我从格式面板中的复选框关闭它,它可以工作 ;但这样,我仍然得到[Not supported by viewer]我的SVG中的输出)我做错了什么?

Sve*_*vak 0

代替:

graph.setCellStyles('html', null);
Run Code Online (Sandbox Code Playgroud)

和:

state.style['html'] = null;
Run Code Online (Sandbox Code Playgroud)