英文:
Thingsboard How to get ${entityName} inside a 'Static Widget (inside a Dashboard State)'
问题
我正在尝试开发一个基于“静态小部件”的小部件。
我可以使用$injector几乎访问所有内容:
var $injector = self.ctx.$scope.$injector;
var attributeService = $injector.get(self.ctx.servicesMap.get('attributeService'));
var assetService = $injector.get(self.ctx.servicesMap.get('assetService'));
我不知道的是如何在“状态仪表板”中使用此小部件,并在其中获取${entityName}
。
有了小部件中的${entityName}
,我可以获取“entityID”和其他所有内容:
assetService.findByName(entityName).subscribe((data) => {
alert(data.id.id);
});
编辑 1:
谢谢 Andreas。我可以获取别名,但在编辑小部件时,小部件不认识它们,因此无法访问JSON的属性。
查看图像描述
提前致谢
英文:
I'm trying to develop a widget based in the 'Static Widget'.
I can access almost everything using $injector:
var $injector = self.ctx.$scope.$injector;
var attributeService = $injector.get(self.ctx.servicesMap.get('attributeService'));
var assetService = $injector.get(self.ctx.servicesMap.get('assetService'));
What I don't know is how can I use this Widget in a 'State Dashboard' and get the ${entityName} inside it.
With the ${entityName} in the Widget I can get the 'entityID' and everything else:
assetService.findByName(entityName).subscribe((data) => {
alert(data.id.id);
});
Edit 1:
Thanks Andreas. I can get the alias but can't go to the properties of the json because the widget doesn't recognized them whem I'm editing the widget.
enter image description here
Thanks in advance
答案1
得分: 0
你可以在resolvedAliases属性中找到与当前仪表板状态关联的设备,如下所示:
self.ctx.dashboard.aliasController.resolvedAliases
在那里,你将看到所有按id声明的仪表板别名,它会像这样:
{
"45a04c6b-1d79-de23-...": {
"alias": "vehiculos",
"entityFilter": {
...
},
"stateEntity": false,
"resolveMultiple": true,
"currentEntity": null
},
"1b02f2a4-5a6c-2cf7-...": {
"alias": "selectedvehicle",
"entityFilter": {
...
},
"stateEntity": true,
"resolveMultiple": false,
"currentEntity": {
"id": "1c90cf60-1a8c-11ee-...",
"entityType": "DEVICE",
"name": "equipo ensamble",
"label": "equipo ensamble"
}
}
}
唯一的前提是要知道你的仪表板别名的id。它们在以下路由中:
self.ctx.dashboard.aliasController.entityAliases
在我这种情况下,当前选定的设备的id是1b02f2a4-1a8c(...)。最后,可以使用以下方式获取设备名称:
self.ctx.dashboard.aliasController.resolvedAliases["1b02f2a4-5a6c-..."].currentEntity.name
希望对你有所帮助。
英文:
You can find the Devices associated to the current dashboard state in the resolvedAliases property following the route:
self.ctx.dashboard.aliasController.resolvedAliases
There you'll see all the declared dashboard alias by id, and it will look like this:
{
"45a04c6b-1d79-de23-...": {
"alias": "vehiculos",
"entityFilter": {
...
},
"stateEntity": false,
"resolveMultiple": true,
"currentEntity": null
},
"1b02f2a4-5a6c-2cf7-...": {
"alias": "selectedvehicle",
"entityFilter": {
...
},
"stateEntity": true,
"resolveMultiple": false,
"currentEntity": {
"id": "1c90cf60-1a8c-11ee-...",
"entityType": "DEVICE",
"name": "equipo ensamble",
"label": "equipo ensamble"
}
}
}
The only prerequisite is to know your dashboard's aliases id. Those are in the route:
self.ctx.dashboard.aliasController.entityAliases
Which was 1b02f2a4-1a8c(...) for the current selected device in my case. Finally can take the Device name with:
self.ctx.dashboard.aliasController.resolvedAliases["1b02f2a4-5a6c-..."].currentEntity.name
Hope being helpful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论