作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道如何从客户端访问属性,但我想从 thingsboard 服务器端访问设备的属性。因此,在开发新的小部件时,我可以显示所有属性的列表并在必要时更改它们。我该怎么做?
最佳答案
我们必须非常清楚服务器端和客户端。事实上,Thingsboard 小部件在浏览器的客户端运行。
据我所知,我们有两个选项可以访问小部件中的属性。
Thingsboard 为使用我们可以像这样使用的 HTTP-Api 提供了一个方便的“服务”:
var entityId, attributeKey, myAttribute, attributeService;
entityId = ... // entity id from the widgets datasource.
attributeKey = 'MyAttribute';
myAttribute = {
key: attributeKey,
value: 'MyAttributeValue';
};
attributeService = self.ctx.$scope.$injector.get('attributeService');
// Access attributes.
attributeService.getEntityAttributesValues('DEVICE', entityId, 'SERVER_SCOPE', attributeKey)
.then(function success(attributes) {
// Use the attribute value.
});
// Write attributes.
attributeService.saveEntityAttributes(
'DEVICE', entityId, 'SERVER_SCOPE', [myAttribute]);
Http-Api 有更多选项,甚至该服务也提供了一些更方便的功能。查看sources of the service atthingsboard/ui/src/app/api/attribute.service.js
注意:这是指低于 3 的 Thingsboard 版本的 ui 模块。
关于attributes - 如何从 thingsboard 服务器端访问属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49950517/
我是一名优秀的程序员,十分优秀!