我希望使用小部件上的自定义操作(单击标记)来更改当前用户的属性“Nr”。
我试图配置以下代码:
let attributeService = widgetContext.$injector.get(widgetContext.servicesMap.get('attributeService'));
let attributes = [{
"key": "Nr",
"value": Nr
}];
attributeService.saveEntityAttributes(entityId, 'SERVER_SCOPE', attributes).
subscribe(
() => {
console.log('Saved!');
},
error => {
console.log('Error');
}
);
但是,如果我手动插入另一个实体Id而不是“org.thingsboard.server.common.data.EntityType.undefined””,则在使用该操作时会得到“No常量entityId”错误。
我也不知道当前用户的实体Id(我认为没有?)
你知道我怎么能解决这个问题吗?
谢谢!
上下文:我有一个带有地图的仪表板,地图左侧是建筑物,右侧是建筑物的细节部件。当我点击地图上的建筑物时,我想要过滤这些细节,以便只保留点击的建筑物的细节。我的想法是从当前用户构建一个具有键名“Nr”的动态过滤器。如果单击建筑物的标记,当前用户的属性“Nr”将更改为单击的建筑物的数量,右边的小部件将只显示单击建筑物的信息。
如果我使用“New多个属性”Widget来更改属性“Nr”,一切都可以正常工作,但我希望使用映射来筛选细节部件。
发布于 2022-08-26 13:05:17
不完全是问题的答案,而是一种更简单的方法来完成您的使用程序,这是由ThingsBoard提供的,而不依赖于自定义操作:
https://thingsboard.io/docs/pe/user-guide/ui/widget-actions/#update-current-dashboard-state
只需使用第二个实体-别名类型“实体从仪表板国家”。每次单击Map中的标记(操作“更新当前仪表板状态”)时,都会更新此别名。那么您就不需要更新任何属性。
发布于 2022-09-01 14:46:00
我抓住你了。Thingsboard需要作为"entityId“,一个类似于这样的JSON:
entityId={
"id": the ID you are tring to put in manually,
"entityType": the type of the entity (written like this "ASSET", "DEVICE" ecc...)
}
你直接给他实体的Id,所以他在寻找entityType,这就是错误信息说的
若要获取当前用户Id,请使用:"self.ctx.currentUser.userId“
或者如果您处于自定义操作中:"widgetContext.currentUser.userId“
所有这些都是:
newEntityId = {};
newEntityId = {"entityType":"USER", "id":self.ctx.currentUser.userId};
attributeService.saveEntityAttributes(newEntityId, 'SERVER_SCOPE', attributes).
subscribe(
() => {
console.log('Saved!');
},
error => {
console.log('Error');
}
);
再见!
https://stackoverflow.com/questions/73500109
复制相似问题