[英]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.