Thingsboard_导航到新的仪表板状态_Widget自定义动作_Javascript代码

时间:2019-02-12 14:09:09

标签: javascript widget dashboard thingsboard

在单击具有相同设备类型的各种设备的不同工具提示(地图)时,是否有人具有自定义操作Javascript代码以导航到新的仪表板状态,从而导致仪表板状态不同。

在我的案例中:我有三个恒温器,我需要处理这三个恒温器上的操作,以打开不同的仪表板状态,但是所有设备的device.type都相同。(Thermostat)

我从仪表板指南视频第2部分中复制了代码,只是将变量“ device.type更改为device.name”,但它不起作用。应该使用If条件(表示特定设备名称的变量或关键字)进行另一种处理。

我也尝试过使用'entityName','device.entityName','device.Name','entityID',device.entityID等,但到目前为止没有任何作用。

自定义操作代码:

var $injector = widgetContext.$scope.$injector;

$injector.get('deviceService').getDevice (entityID.id).then(function(device) {

      if (device.name == 'thermostat1') {                    

          openDashboardState ('Thermostat1');

      } else if (device.name == 'thermostat2') {

          openDashboardState('Thermostat2');

      } else if (device.name == 'thermostat3') {

          openDashboardState('Thermostat3');

      }

});

function openDashboardState(stateId) {

    var params = {
        entityId: entityId,
        entityName: entityName
    };

    Widgetcontext.statecontroller.openState(stateId, params, false);
}

我是Javascript和前端开发的初学者。 Thingsboard上的任何JS开发人员或专家都可以帮助我吗?太好了。

谢谢。

最好的问候,

唐兹

1 个答案:

答案 0 :(得分:0)

最后,它可以与'device.name'一起使用。这是一个错字错误。 现在,我在代码中发现了区分大小写的错误并进行了纠正。

最好的问候, 唐加拉吉