如何检查jointJS元素不是基于类型,而是基于模板名称

How to check a jointJS element not based on type but on stencil name instead

本文关键字:类型 于模板 何检查 jointJS 检查 元素 于类型      更新时间:2023-09-26

我想在Rappid 做一个检查,当插入一个元素在Paper,如果这个元素是工作项或活动,但唯一类似的检查我发现在Rappid文档是:

if (cell.get('type') !== 'link'){//Do something}

检查该元素是否为链接。是否有任何方法来检查不基于'type',但基于'name'代替(其中的名字是基本形状的模板名称之一)?

我的意思是我将如何检查一个元素是一个形状与模板名称活动或工作项?

我可以在我的代码中执行此检查,因为到目前为止,我尝试在创建我的halo中插入一行代码,我不能。我甚至不能这样做cell.set('wi_name', "ACTIVITY");设置一个名为wi_name的检查器字段,名称为Activity)

我是这样解决的:

if (cell.get('type') === 'basic.Rect'){}

其中basic.Rect为基本形状,名称为ActivityWorkitem,如模板中所述。

该类型也可以通过对象属性:

直接检索。
if (cell.attributes.type === 'basic.Rect'){}

请注意,如果您正在查看ElementView对象(例如,在扩展ElementView以创建约束时使用this),您需要访问model:

if (elem.model.attributes.type === 'basic.Rect'){}

或:

if (elem.model.get('type') === 'basic.Rect'){}