1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <meta charset="utf-8" />
5
    <title>Wialon Playground - Get units</title>
6
    <script type="text/javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
7
    <script type="text/javascript" src="//hst-api.wialon.com/wsdk/script/wialon.js"></script>
8
</head>
9
<body>
10
11
Select unit: <select id="units"><option></option></select>
12
<div id="log"></div>
13
14
</body>
15
</html>
HTML
2
 
1
#log { border: 1px solid #c6c6c6; }
2
.icon {float:left; margin:10px;}
CSS
69
 
1
// Print message to log
2
function msg(text) { $("#log").prepend(text + "<br/>"); }
3
4
function init() { // Execute after login succeed
5
    var sess = wialon.core.Session.getInstance(); // get instance of current Session
6
    // flags to specify what kind of data should be returned
7
    var flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.lastMessage;
8
9
    sess.loadLibrary("itemIcon"); // load Icon Library  
10
    sess.updateDataFlags( // load items to current session
11
    [{type: "type", data: "avl_unit", flags: flags, mode: 0}], // Items specification
12
        function (code) { // updateDataFlags callback
13
            if (code) { msg(wialon.core.Errors.getErrorText(code)); return; } // exit if error code
14
15
            // get loaded 'avl_unit's items  
16
            var units = sess.getItems("avl_unit");
17
            if (!units || !units.length){ msg("Units not found"); return; } // check if units found
JS
Result
Source code of example Close ✕
1
 
1
/*source*/