필드를 내 엔티티의 각 속성에 적용하려고합니다. Orion을 Quering하고 엔티티를 가져 오는 것은 문제가되지 않습니다. (NGSI Source 위젯을 통해이 작업을 수행합니다.)하지만 이러한 매개 변수를 가져 오는 방법입니다. NGSI 소스 (오리온 인스턴스에 대한 일반적인 suscription)에서 JavaScript (WireCloud)에서 OCB 쿼리하기
:var doInitialSubscription = function doInitialSubscription() {
this.subscriptionId = null;
this.ngsi_server = MashupPlatform.prefs.get('ngsi_server');
this.ngsi_proxy = MashupPlatform.prefs.get('ngsi_proxy');
this.connection = new NGSI.Connection(this.ngsi_server, {
ngsi_proxy_url: this.ngsi_proxy
});
var types = MashupPlatform.prefs.get('ngsi_entities').split(new RegExp(',\\s*'));
var entityIdList = [];
var entityId;
for (var i = 0; i < types.length; i++) {
entityId = {
id: '.*',
type: types[i],
isPattern: true
};
entityIdList.push(entityId);
}
var attributeList = null;
var duration = 'PT3H';
var throttling = null;
var notifyConditions = [{
'type': 'ONCHANGE',
'condValues': MashupPlatform.prefs.get('ngsi_update_attributes').split(new RegExp(',\\s*'))
}];
var options = {
flat: true,
onNotify: handlerReceiveEntity.bind(this),
onSuccess: function (data) {
this.subscriptionId = data.subscriptionId;
this.refresh_interval = setInterval(refreshNGSISubscription.bind(this), 1000 * 60 * 60 * 2); // each 2 hours
window.addEventListener("beforeunload", function() {
this.connection.cancelSubscription(this.subscriptionId);
}.bind(this));
}.bind(this)
};
this.connection.createSubscription(entityIdList, attributeList, duration, throttling, notifyConditions, options);
};
var handlerReceiveEntity = function handlerReceiveEntity(data) {
for (var entityId in data.elements) {
MashupPlatform.wiring.pushEvent("entityOutput", JSON.stringify(data.elements[entityId]));
}
};
MyWidget 사람 : 나는 유형 필드의 값을 얻을 비슷한 코드를하려고 해요
MashupPlatform.wiring.registerCallback("entityInput", function (entityString) {
var entity;
entity = JSON.parse(entityString);
id = entity.id;
type = entity.type;
for(var attr in entity){
attribute = entity[attr];
}
. 어떻게해야합니까? (확실 합니다만 ...)
'entityString' 변수의 내용을 추가하여 질문을 편집하여 사례를 더 잘 이해할 수 있습니까? – fgalan
@fgalan 그 이유는 다음과 같습니다. '{ "id": "387243781", "type": "MyApp", "BAT": "65", "value1": "351", "value2" : "0.023", "value3": "0.039", "value4": "37.375476", "value5": "- 5.989363", "date": "23/11/2014 13:26:27" : "Parque de María Luisa 41013 Sevilla"}'. 엔티티의 이름 및 값 필드 만 검색하고 있습니다. 나는 또한 내가 오리온을 통해 변화에 매달리는 방식을 덧붙였다. 내가 뭔가 잘못하고 있는거야? –