mirror of
https://gitee.com/antv/g6.git
synced 2024-11-29 18:28:19 +08:00
feat: add getElementData api (#5814)
This commit is contained in:
parent
3f4810d9ae
commit
e932c0ac7b
@ -134,6 +134,11 @@ describe('Graph', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('getElementData', () => {
|
||||
expect(graph.getElementData('node-1').id).toEqual('node-1');
|
||||
expect(graph.getElementData(['node-1']).map(idOf)).toEqual(['node-1']);
|
||||
});
|
||||
|
||||
it('getXxxData/addXxxData/updateXxxData/removeXxxData', () => {
|
||||
expect(graph.getNodeData('node-1').id).toEqual('node-1');
|
||||
expect(graph.getNodeData(['node-1']).map(idOf)).toEqual(['node-1']);
|
||||
|
@ -442,6 +442,28 @@ export class Graph extends EventEmitter {
|
||||
return this.context.model.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* <zh/> 获取单个元素数据
|
||||
*
|
||||
* <en/> Get element data by ID
|
||||
* @param id - <zh/> 元素 ID | <en/> element ID
|
||||
* @returns <zh/> 元素数据 | <en/> element data
|
||||
* @apiCategory data
|
||||
*/
|
||||
public getElementData(id: ID): ElementDatum;
|
||||
/**
|
||||
* <zh/> 批量获取多个元素数据
|
||||
*
|
||||
* <en/> Get multiple element data in batch
|
||||
* @param ids - <zh/> 元素 ID 数组 | <en/> element ID array
|
||||
* @apiCategory data
|
||||
*/
|
||||
public getElementData(ids: ID[]): ElementDatum[];
|
||||
public getElementData(ids: ID | ID[]): ElementDatum | ElementDatum[] {
|
||||
if (Array.isArray(ids)) return ids.map((id) => this.context.model.getElementDataById(id));
|
||||
return this.context.model.getElementDataById(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* <zh/> 获取所有节点数据
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user