Home > SCH_PrimitiveAttribute > getAll
SCH_PrimitiveAttribute.getAll() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取所有属性
签名
typescript
function getAll(parentPrimitiveId?: string): Promise<Array<ISCH_PrimitiveAttribute>>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
parentPrimitiveId | string | (可选) 父图元 ID |
返回值
Promise<Array<ISCH_PrimitiveAttribute>>
属性图元对象数组
备注
不传递父图元 ID 将拿到图页中的所有属性图元
示例
javascript
// 1. 放置一个测试器件(属性图元随器件生成,无法单独创建)
const devices = await eda.lib_Device.search('');
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const comp = await eda.sch_PrimitiveComponent.create(devices[0], x, y);
const compId = comp.getState_PrimitiveId();
// 2. 传父图元 ID,拿到该器件的全部属性
const compAttrs = await eda.sch_PrimitiveAttribute.getAll(compId);
const keys = compAttrs.map(a => a.getState_Key());
// 3. 不传参数,拿到当前图页上的所有属性图元
const allAttrs = await eda.sch_PrimitiveAttribute.getAll();
// 4. 清理测试器件(属性图元随器件一起删除)
await eda.sch_PrimitiveComponent.delete([compId]);
console.log('component attr count:', compAttrs.length);
console.log('keys:', keys.join(', '));
console.log('page total attrs:', allAttrs.length);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20