Skip to content

Instantly share code, notes, and snippets.

View m-yahya's full-sized avatar
🛠️
Building Stuff

Muhammad Yahya m-yahya

🛠️
Building Stuff
View GitHub Profile
@m-yahya
m-yahya / ui-tree_6.js
Created April 28, 2021 15:15
Tutorial: Nested UI from JSON data and Tree view
const data = {
Parent: ["Child 1", "Child 2", {Child3:'Sub Child'}],
};
// OR
const data = {
Parent: {
Child1: "Child 1",
Child2: {Child21: "Child 21", Child22: "Child 22"},
Child3: [
"Child 31",
@m-yahya
m-yahya / ui-tree_5.js
Created April 28, 2021 15:15
Tutorial: Nested UI from JSON data and Tree view
// evaluate expressions
const createList = (items) => {
// code removed for brevity
case "array":
items.forEach((item) => {
createList(item);
});
break;
}
};
@m-yahya
m-yahya / ui-tree_4.js
Created April 28, 2021 15:14
Tutorial: Nested UI from JSON data and Tree view
// call the function on page load
window.onload = () => {
createList(data);
markupArray.push("</ul>");
$("#list").html(markupArray.join(""));
};
@m-yahya
m-yahya / ui-tree_3.js
Created April 28, 2021 15:13
Tutorial: Nested UI from JSON data and Tree view
// evaluate expressions
const createList = (items) => {
switch ($.type(items)) {
case "object":
getItems(items);
break;
case "string":
markupArray.push(`<li> <span> ${items} </span> </li>`);
break;
case "array":
@m-yahya
m-yahya / ui-tree_2.js
Last active April 28, 2021 15:11
Tutorial: Nested UI from JSON data and Tree view
// get items in the object
const getItems = (items) => {
for (const item in items) {
// push li tags for parent
// with nested opening ul tag for children
markupArray.push(`<li> <a> ${item} </a> <ul>`);
// evaluate expression for children
createList(items[item]);
// push closing tage
markupArray.push("</ul></li>");
@m-yahya
m-yahya / ui-tree_1.js
Last active April 28, 2021 15:11
Tutorial: Nested UI from JSON data and Tree view
// create list function
const createList = (items) => {
switch ($.type(items)) {
case "object":
console.log(items);
break;
case "string":
console.log(items);
break;
case "array":
@m-yahya
m-yahya / createList_1.js
Created April 28, 2021 14:49
Dynamic Nested UI and Tree View Tutorial
const createList = (items) => {
switch ($.type(items)) {
case "object":
console.log(items);
break;
case "string":
console.log(items);
break;
case "array":
console.log(items);
const CPOs = {
'StarCharge': {
name: 'StarCharge',
title: 'CPO',
children: [
{
name: 'SC_CS1',
title: 'Charging Station',
children: [
{
@m-yahya
m-yahya / TestVars.js
Last active July 27, 2020 07:29
Building dApp’s Backend with Node.js and Webpack
// test variables
let contract
const owner = accounts[0]
const user = accounts[1]
const notOwner = accounts[2]
const unregistered = accounts[3]
const name = 'John Doe'
const age = 25
const value = 100
// global contract instance
@m-yahya
m-yahya / TestSend.js
Last active July 27, 2020 07:32
Building dApp’s Backend with Node.js and Webpack
it('should send the random value', async () => {
// register user
await contract.registerUser(user, name, age, {
from: owner,
})
// send the production value
let result = await contract.send(value, {
from: user,
})
// test event