如何将类添加到JointJS单元格?

Joa*_*ner 7 svg jointjs

我可以使用该attr方法来更改单元格的属性,例如设置链接的笔划:

conn.attr({'.connection': { stroke: 'red' }});
Run Code Online (Sandbox Code Playgroud)

但我宁愿在css文件中设置这样的属性,例如在此

.connection {
    stroke: #999;
}

.connection.error {
    stroke: #F00;
}
Run Code Online (Sandbox Code Playgroud)

有没有办法将这些类添加到生成的SVG?

我试过了

conn.attr({'.connection': { class: 'error' }});
Run Code Online (Sandbox Code Playgroud)

但这会删除.connection 课程,这很重要.它可以写作

conn.attr({'.connection': { class: 'connection error' }});
Run Code Online (Sandbox Code Playgroud)

但显然不会扩展为具有多个正交类(error,highlighted...)

Joa*_*ner 3

在官方演示之一中我找到了这段代码:

function toggleLive(model, signal) {
    // add 'live' class to the element if there is a positive signal
    V(paper.findViewByModel(model).el).toggleClass('live', signal > 0);
}
Run Code Online (Sandbox Code Playgroud)

我必须说,在我看来,以这种方式直接与视图交互似乎违反了模型视图分离,但如果在官方代码中使用这种方式,那么我得出结论,这是最惯用的方式。