首页 文章

NGSI更新了Wirecloud中复杂实体的属性

提问于
浏览
2

是否可以通过Wirecloud NGSI API中的updateAttributes()函数更新子属性?

例如,这个实体中的坐标(entity.location.coords.coordinates [0] = - 2.000000) .

"attrNames": [ "A1", "A2", "position" ],
   "creDate": 1389376081,
   "modDate": 1389376244,
   "location": {
       "attrName": "position",
       "coords": {
           "type": "Point",
           "coordinates": [ -3.691944, 40.418889 ]
       }

EDITED

我自己的答案:可以通过传递一个对象作为属性的值 .

ngsi.updateAttributes([
                    {
                        'entity': {'id': "entity-id"},
                        'attributes':[{ 
                          "name":"location","contextValue": {
                               "attrName": "position",
                               "coords": {
                                     "type": "Point",
                                     "coordinates": [ -2.000000, 40.418889 ]
                               }
                          } 
                        }]  
                    }
                ], {
                    onSuccess: onUpdateAttributesSuccess,
                    onFailure: onUpdateAttributesFail
                }
            );

但是, Wirecloud is using NGSI API v1 ,因此 all attributes are treated as strings 当他们被发送/接收到Orion时 .

更多信息:http://fiware-orion.readthedocs.io/en/master/user/structured_attribute_valued/

1 回答

  • 0

    目前,使用WireCloud的NGSI API无法对结构属性进行部分更改 . 此外,据我所知,NGSI API没有提供直接的方式来对结构化属性(v1和v2)进行部分更新 .

    但是, v1 of the NGSI API supports structured attribute values . 因此,您可以使用 updateContext 方法仅更新一个属性(例如 coordinates 属性) . 唯一需要考虑的是你必须提供完整的值,所以如果你想进行部分更改,你必须读取值,进行部分更改并更新它 .

    事实上,你几乎让它工作 . 您只需要修改传递要更新的属性的方式,就应该将它们包装到一个数组中:

    ngsi.updateAttributes([{
            "entity": {"id": "entity-id"},
            "attributes": [
                {
                    "name": "location",
                    "contextValue": {
                        "attrName": "position",
                        "coords": {
                            "type": "Point",
                            "coordinates": [-2.000000, 40.418889]
                        }
                    }
                }
            ]
        }],
        {
            onSuccess: onUpdateAttributesSuccess,
            onFailure: onUpdateAttributesFail
        }
    );
    

相关问题