var flat = [
{id: 1, name: 'Категория 0-1', parent: 0},
{id: 2, name: 'Категория 0-2', parent: 0},
{id: 3, name: 'Категория 0-3', parent: 0},
{id: 4, name: 'Категория 1-1', parent: 1},
{id: 5, name: 'Категория 1-2', parent: 1}
];
var els = [];
var tree = [];
for (var i = 0; i < flat.length; i++) {
flat[i].childs = [];
if (flat[i].parent == 0) {
tree.push(flat[i]);
} else {
els[flat[i].parent].childs.push(flat[i]);
}
els[flat[i].id] = flat[i];
}
console.log(tree);
var str = '{"success":1,"items":{"Orb of Deliverance":{"price":36.8,"appid":"570"},"Planks of the Bogatyr":{"price":0.2,"appid":"570"},"Virulent Matriach":{"price":921.27,"appid":"570"}}}';
var obj = JSON.parse(str);
var price = obj.items['Planks of the Bogatyr'].price;
console.log(price);
<a href='' id='report-link' download style='display: none;'></a>
В JS:var data = new FormData();
data.append('file', document.getElementById('file').files[0]);
var post = new XMLHttpRequest();
post.open('POST', 'where/to/send', true);
post.onreadystatechange = function() {
if (post.readyState != 4) {
return;
}
hideSpinner();
switch (post.status) {
case 200:
var a = document.getElementById('report-link');
a.href = '/get/file/from&id=' + post.responseText;
a.click();
break;
...
}
}
showSpinner();
post.send(data);