Home > SCH_PrimitiveText > get
SCH_PrimitiveText.get() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
获取文本
签名
typescript
function get(primitiveIds: string): Promise<ISCH_PrimitiveText | undefined>;1
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveIds | string | 文本的图元 ID,可以为字符串或字符串数组,如若为数组,则返回的也是数组 |
返回值
Promise<ISCH_PrimitiveText | undefined>
文本图元对象,undefined 表示获取失败
示例
javascript
// 1. 在画布空白处创建两个测试文本(随机坐标避免重合)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const text1 = await eda.sch_PrimitiveText.create(x, y, '嘉立创示例_文本A', 0, '#FF0000');
const text2 = await eda.sch_PrimitiveText.create(x, y + 300, '嘉立创示例_文本B', 0, '#0000FF');
const id1 = text1.getState_PrimitiveId();
const id2 = text2.getState_PrimitiveId();
// 2. 传单个 ID 字符串,返回单个文本对象
const single = await eda.sch_PrimitiveText.get(id1);
// 3. 传 ID 数组,返回文本对象数组(任一 ID 未匹配不影响其它图元的返回)
const arr = await eda.sch_PrimitiveText.get([id1, id2]);
// 4. 清理测试文本(查询类需要清理)
await eda.sch_PrimitiveText.delete([id1, id2]);
console.log('single content:', single.getState_Content());
console.log('single color:', single.getState_TextColor());
console.log('array length:', arr.length);
console.log('textB content:', arr[1].getState_Content());
console.log('textB color:', arr[1].getState_TextColor());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22