簡體   English   中英

NGSI更新Wirecloud中復雜實體的屬性

[英]NGSI update attributes from complex entities in Wirecloud

是否可以通過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使用的是NGSI API v1 ,因此,當所有屬性發送到Orion或從Orion接收時, 所有屬性都被視為字符串

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

當前,無法使用WireCloud的NGSI API對結構屬性進行部分更改。 而且,據我所知,NGSI API並沒有提供對結構化屬性(v1和v2均未進行部分更新)的直接方法。

但是, NGSI API的v1支持結構化屬性值 因此,您可以利用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
    }
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM