如何编辑资产名称?

How edit asset name?

如何编辑资产名称?它不起作用。谢谢

让 assetService = $injector.get(self.ctx.servicesMap.get('assetService'));
让 activeID = self.ctx.data[0].datasource.entityId
让 tenantId = self.ctx.dashboard.authUser.tenantId

let asset = {
    additionalInfo: null,
    createdTime: 1599121131415, // временно
    customerId: {
        entityType: "CUSTOMER",
        id: self.ctx.dashboard.authUser.customerId
    },
    id: {
        entityType: "ASSET",
        id: activeID
    },
    label: null,
    name: "kuku", // временно
    tenantId: {
        entityType: "TENANT",
        id: tenantId
    },
    type: "справочник"
}

assetService.saveAsset(资产)

Thingsboard 当前使用 Angular 10 个 See releases 构建。您正确地注入了 Angular 服务 'assetService'。您需要按照 Angular 方法从 assetService 订阅可观察对象。

通话中

assetService.saveAsset(asset)

不订阅意味着什么都不会发生。来自 Angular University Blog

The multiple versions of the Angular HTTP module all have an RxJS Observable-based API. This means that the multiple calls to the HTTP module will all return an observable, that we need to subscribe to one way or the other.

所以这是 'subscribe' 到上述可观察对象的代码

assetService.saveAsset(asset).subscribe(
    (response) => {
        console.log(
            "saveAsset call Success:",
            response);
    },
    response => {
        console.log(
            "saveAsset call Error:",
            response);
    },
    () => {
        console.log(
            "saveAsset observable Complete"
        );
});

如果上面的代码有错误请告诉我,我没有测试过。并感谢您的问题 Anzor - 它引导我找到一个解决方案来制作自定义 Thingsboard 小部件以及 Widgets Development Guide.