簡體   English   中英

從JavaScript查詢OCB(WireCloud)

[英]Querying OCB from JavaScript (WireCloud)

我正在嘗試為實體的每個屬性獲取類型字段。 查詢Orion並獲取實體不是問題(我通過NGSI Source小部件完成此任務),而是獲取這些參數的方式。

從NGSI來源(通常為Orion實例訂閱):

 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];
    }

我正在嘗試編寫類似的代碼來獲取類型字段的值。 我怎樣才能做到這一點? (我敢肯定這很容易...)

如果要獲取屬性的類型元數據,則不能使用當前的NGSI源操作符實現(至少v3.0.2),因為NGSI源使用flat選項(丟棄該信息)。

我們正在研究更新此運算符,以允許在不使用flat選項的情況下創建訂閱。 這里的主要問題是其他組件期望使用flat選項時以返回的格式提供此運算符提供的數據。 在深入分析問題之后,我將更新此答案。

暫無
暫無

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

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