我希望Rapid在插入Paper中的元素时进行检查,如果此元素是Workitem或Activity,但我在Rapid文档中找到的唯一类似检查是:
if (cell.get('type') !== 'link'){//Do something}
检查此元素是否为链接。有没有办法检查不是基于'type'
而是基于'name'
(其中'name是基本形状的模板名称之一)?
我的意思是如何检查元素是否是具有模板名称Activity或Workitem的形状?
我可以在我的代码中执行此检查,因为我在创建我的halo
到目前为止插入一行代码并且我不能。(例如我甚至不能这样做cell.set('wi_name', "ACTIVITY");
来设置检查器字段名称为wi_name,名称为Activity)
我这样解决了我的问题:
if (cell.get('type') === 'basic.Rect'){}
其中basic.Rect
是模板中所述的基本形状,其名称为Activity
或Workitem
。
也可以通过对象属性直接检索类型:
if (cell.attributes.type === 'basic.Rect'){}
请注意,如果您正在查看ElementView
对象(例如,在this
事件中使用extending ElementView to create constraints),则需要访问model
:
if (elem.model.attributes.type === 'basic.Rect'){}
要么:
if (elem.model.get('type') === 'basic.Rect'){}