群组元数据
为群组附加结构化的自定义数据,用于组织管理与应用特定逻辑。
备注
在 userInstance 上通过 getGroupById 或 getGroupByName 来获取 group,参见获取群组。
本模块的功能
更新群组的元数据(键值对字段),例如房间名称、标签,或任何与 RainMaker 内置组字段分离的、可序列化为 JSON 的应用数据。
使用场景: 当 UI 按自定义属性筛选或展示群组,而这些属性无法通过 name 或 description 表示时,可以使用此功能。
在 createGroup 上使用 customData 可在创建群组时设置元数据,详见管理群组。
预期结果: 元数据会存储在群组上,并在后续获取群组时返回(前提是该 API 支持包含该元数据)。
常见工作流
更新元数据
const group = await userInstance.getGroupById({ groupId: "group_id_123" });
await group.updateMetadata({
room: "kitchen",
floor: 1,
lastUpdated: new Date().toISOString(),
});
创建时设置元数据
await userInstance.createGroup({
name: "Kitchen Devices",
nodeIds: [],
customData: { room: "kitchen", icon: "chef" },
});
错误处理
try {
await group.updateMetadata(metadata);
} catch (error) {
console.error("Failed to update group metadata:", error);
}

