Skip to content

Nested observable dictionary #12

@Draqun

Description

@Draqun

Hi.

I need put to frontend observable dictionary with few nested observable dictionary. So my code looks like

var DevicesViewModel = function(node) {
        var self = this;
        self.node = node;
        self.devices_commands = ko.observableDictionary({});

        self.addDevice = function(device) {
            self.devices_commands.push(device, ko.observableDictionary({}));
        };

        self.parse_cmd = function(cmd) {
            var device_name = cmd["device"];
            if(-1 == self.devices_commands.indexOf(device_name)) { self.addDevice(device_name); }
            self.devices_commands.get(device_name)().set(cmd["cmd_type"], cmd);

            if(cmd["cmd_type"] == "AT^SMONI") { parse_st_smoni(cmd); }
            else if(cmd["cmd_type"] == "AT^MONI") { parse_at_moni(cmd); }
            else if(cmd["cmd_type"] == "AT^SMONP") { parse_at_smonp(cmd); }
        };
    };

This is my temaplete

<div id="devices" class="row" data-bind="foreach: devices_commands.items">
    <div class="col-xs-12 col-sm-12 col-md-6 col-md-offset6" data-bind="attr: {id: key}">
        <div class="">
            <h3 data-bind="text: key"></h3>
            <div data-bind="with: value">
                <div data-bind="with: $parent.get('AT^MONI')">
                    <div data-bind="text: 'cmd_response'"></div>
                </div>
            </div>
            <div data-bind="text: ko.toJSON(value)">
            </div>
        </div>
    </div>
</div>

And data printed in last div

{"ATI":{"timestamp":1496913515.8213873,"cmd_type":"ATI","device":"dUsb","cmd_response":["Cinterion","ALAS3-W","REVISION 00.002"]},"AT^MONI":{"timestamp":1496913516.244922,"cmd_type":"AT^MONI","device":"dUsb","cmd_response":{"SRxLev":"48","EC/n0":"-7.0","connection_status":"No connection","PSC":"12","SQual":"22","CSGid":"--","MCC":"260","UARFCN":"2963","LAC":"A044","MNC":"01","cell":"0C82A45","RSCP":"-66","dedicated_channel":{"ComMod":null,"HSUPA":null,"EC/n0":null,"PhysCh":null,"HSDPA":null,"Slot":null,"SF":null,"RSCP":null},"Mode":"FDD"}},"AT^SMONI":{"timestamp":1496913516.8948753,"cmd_type":"AT^SMONI","device":"dUsb","cmd_response":["3G","FDD","2963","12","-6.5","-65","260","01","A044","0C82A45","23","49","--","NOCONN"]},"AT^SMONP":{"timestamp":1496913517.108912,"cmd_type":"AT^SMONP","device":"dUsb","cmd_response":{"4G":[["1300","-17.0","-123","5","132","0"],["1300","-17.0","-127","1","291","0"]],"2G":[["41","----","-","-","----","------"],["3","----","-","-","----","------"],["14","----","-","-","----","------"],["4","----","-","-","----","------"],["12","----","-","-","----","------"],["40","----","-","-","----","------"]],"3G":[["2963","12","-6.5","-75","-","-","AS","-1"],["2963","121","-24.0","83","-","-","SN","-32768"],["10737","152","-15.0","-84","-","-3","SN","-32768"],["10737","0","-20.0","-90","-","-7","SN","-32768"],["10762","0","-14.0","-84","-","-3","SN","-32768"],["10762","152","-24.0","-93","-","-7","SN","-32768"],["10762","112","-24.0","-94","-","-7","SN","-32768"]]}},"AT^SIND?":{"timestamp":1496913512.909214,"cmd_type":"AT^SIND?","device":"dUsb","cmd_response":[["signal","0","99"],["service","0","1"],["sounder","0","0"],["message","0","0"],["roam","0","0"],["smsfull","0","0"],["audio","0","0"],["simstatus","1","5"],["simdata","0"],["eons","0","3","\"0050006C00750073\"","\"\"","0"],["nitz","0","\"00310037002F00300036002F00300037002C00300035003A00340038003A00320039\"","+08","1"],["psinfo","0","6"],["simlocal","0","1","0"],["lsta","0","0"],["pacsp","0","99"],["steerroam","0"],["pagingcoor","0","1"],["ceer","0","0"],["iccid","0","\"8948011714275163850\""],["euiccid","0","\"\""],["imsi","0","\"260011701124460\""],["ltebot","0","0","0","\"\""],["prov","1","1","\"fallback*\""],["simread","0","0","7"]]},"AT+CEER":{"timestamp":1496913513.3323739,"cmd_type":"AT+CEER","device":"dUsb","cmd_response":["EMM attach failed"]},"AT+GSN":{"timestamp":1496913515.610146,"cmd_type":"AT+GSN","device":"dUsb","cmd_response":"004401081597557"},"AT+COPS?":{"timestamp":1496913517.7437313,"cmd_type":"AT+COPS?","device":"dUsb","cmd_response":["0","0","\"0050006C00750073\"","2"]}}

I want create panel for every command, with timestamp and data from cmd_response variable. As you see there is a lot of type this data. Sometimes this is list, sometimes dictionary.

Can anyone tell me how I should get this nested data?

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions