A Pen by Johannes Brüderl on CodePen.
Last active
January 11, 2019 20:27
-
-
Save birdayz/56e791513a2860af80594d46c0a6d195 to your computer and use it in GitHub Desktop.
Infinimesh recursive object transformation for vuetify tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="app"> | |
<v-app id="inspire"> | |
<v-treeview :items="items"></v-treeview> | |
</v-app> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function transformObject(input) { | |
var res = {}; | |
res.id = input.uid; | |
res.name = input.name; | |
res.children = []; | |
if (input.devices) { | |
for (var device of input.devices) { | |
res.children.push(transformObject(device)); | |
} | |
} | |
if (input.objects) { | |
for (var object of input.objects) { | |
res.children.push(transformObject(object)); | |
} | |
} | |
return res; | |
} | |
function transform(input) { | |
var res = []; | |
for (var value of input.objects) { | |
var el = transformObject(value); | |
res.push(el) | |
} | |
for (var value of input.devices) { | |
var el = transformObject(value); | |
res.push(el) | |
} | |
return res; | |
} | |
var data = { | |
"objects": [{ | |
"uid": "0x1119d", | |
"name": "Johannes' Home", | |
"objects": [{ | |
"uid": "0x1119e", | |
"name": "First Floor", | |
"objects": [{ | |
"uid": "0x1119f", | |
"name": "Living Room", | |
"devices": [{ | |
"uid": "0x111a0", | |
"name": "PC" | |
}] | |
}] | |
}, | |
{ | |
"uid": "0x111a3", | |
"name": "Second Floor" | |
} | |
], | |
"devices": [{ | |
"uid": "0x111a4", | |
"name": "le lamp" | |
}] | |
}, | |
{ | |
"uid": "0x111a5", | |
"name": "Enclosing Room", | |
"devices": [{ | |
"uid": "0x111a6", | |
"name": "Enclosing-room-device" | |
}] | |
} | |
], | |
"devices": [{ | |
"uid": "0x111a2", | |
"name": "some device" | |
}] | |
}; | |
new Vue({ | |
el: '#app', | |
data: () => ({ | |
items: transform(data) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet" /> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet" /> |
A Pen by Johannes Brüderl on CodePen.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment