What are the lodash combinations to achieve the below scenario? - javascript

I get below data from twitter in which you can see it has multilevel array in it.I need a single array which has all the objects in it.You can find below how i need the data to be shown.
[
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}],
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}],
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}]
]
but I need to loop only single array like this having all the data combined in single array.
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
},
{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}]

Use _.flatten(arr, isDeep)
Flattens a nested array. If isDeep is true the array is recursively flattened, otherwise it’s only flattened a single level.
var flattenedArr = _.flatten(arr);
If your array is nested then use the true as second argument for deep flatten.
var flattenedArr = _.flatten(arr, true);
Demo
var arr = [
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}],
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}],
[{
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}, {
"created_at": "Tue May 19 04:36:36 +0000 2015",
"id": "asdfasdf",
"id_str": "ASdfasdfasdf"
}]
];
console.log(_.flatten(arr));
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>

Related

Rearrange list of JavaScript array of objects with children list into one object with the parent details inserted inside the child list

for example, let's say I have the below array of javascript objects that has a parent list and child list...
let accessories = [
{
"storeid": "1",
"storename": "Novare station one",
"computers": [
{
"name": "Elite book",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "HP Envy",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "Macbook Pro",
"status": "available",
"date": "Sat Jul 02 2022"
}
]
},
{
"storeid": "2",
"storename": "Novare central",
"computers": [
{
"name": "HP workstation",
"status": "available",
"date": "Wed Jul 06 2022"
},
{
"name": "Macbook air",
"status": "available",
"date": "Wed Jul 06 2022"
}
]
}
]
And I want to rearrange the above list to form the below single object with the parent object details added to the child list
let accessories = [
{
"storeid": "1",
"storename": "Novare station one",
"name": "Elite book",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"storeid": "1",
"storename": "Novare station one",
"name": "HP Envy",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"storeid": "1",
"storename": "Novare station one",
"name": "Macbook Pro",
"status": "available",
"date": "Sat Jul 02 2022"
},
{
"storeid": "2",
"storename": "Novare central",
"name": "HP workstation",
"status": "available",
"date": "Wed Jul 06 2022"
},
{
"storeid": "2",
"storename": "Novare central",
"name": "Macbook air",
"status": "available",
"date": "Wed Jul 06 2022"
},
]
I don't know if this is even possible but any assistance will be highly appreciated.
You can try below code it should work for you.
const accessories = [
{
"storeid": "1",
"storename": "Novare station one",
"computers": [
{
"name": "Elite book",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "HP Envy",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "Macbook Pro",
"status": "available",
"date": "Sat Jul 02 2022"
}
]
},
{
"storeid": "2",
"storename": "Novare central",
"computers": [
{
"name": "HP workstation",
"status": "available",
"date": "Wed Jul 06 2022"
},
{
"name": "Macbook air",
"status": "available",
"date": "Wed Jul 06 2022"
}
]
}
]
const mappedData = [];
(accessories || []).forEach(item => {
const values = item.computers;
values.forEach(value => (mappedData.push({
storeid: item.storeid,
storename: item.storename,
name: value.name,
status: value.status,
date: value.date,
})))
});
console.log("accessoriesMappedData", mappedData)
you can combine use flatMap and map same as :
let accessories = [
{
"storeid": "1",
"storename": "Novare station one",
"computers": [
{
"name": "Elite book",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "HP Envy",
"status": "available",
"date": "Tue Jun 14 2022"
},
{
"name": "Macbook Pro",
"status": "available",
"date": "Sat Jul 02 2022"
}
]
},
{
"storeid": "2",
"storename": "Novare central",
"computers": [
{
"name": "HP workstation",
"status": "available",
"date": "Wed Jul 06 2022"
},
{
"name": "Macbook air",
"status": "available",
"date": "Wed Jul 06 2022"
}
]
}
]
const result = accessories.flatMap(({computers, ...rest}) => computers.map(ele => ({...rest, ...ele})))
console.log(result)
const accessories = [
{
'storeid': '1',
'storename': 'Novare station one',
'computers': [
{
'name': 'Elite book',
'status': 'available',
'date': 'Tue Jun 14 2022'
},
{
'name': 'HP Envy',
'status': 'available',
'date': 'Tue Jun 14 2022'
},
{
'name': 'Macbook Pro',
'status': 'available',
'date': 'Sat Jul 02 2022'
}
]
},
{
'storeid': '2',
'storename': 'Novare central',
'computers': [
{
'name': 'HP workstation',
'status': 'available',
'date': 'Wed Jul 06 2022'
},
{
'name': 'Macbook air',
'status': 'available',
'date': 'Wed Jul 06 2022'
}
]
}
]
const result = accessories.flatMap(item =>
item.computers.map(element =>
Object.assign({ 'storeid': item['storeid'], 'storename': item['storename'] }, element)
)
)
console.log(result)

Filter includes false is not a function

I am searching an array within my object to return an object with only the matched values in my categories array using filter & includes. For some reason whenever I try to run my function keep getting
TypeError: Cannot read property 'includes' of null
or
TypeError: false is not a function
if I use the find function within my filter.
What am I doing wrong?
[{
"entryTitle": "What Is Sports Medicine Acupuncture?",
"date": "September 30 2015",
"categories": ["Knee Pain"],
"type": false
}, {
"entryTitle": "Providing Quality Care During The COVID-19 Pandemic",
"date": "March 23 2020",
"categories": null,
"type": false
}, {
"entryTitle": "Correcting Severe Antalgic Posture & Gait",
"date": "May 09 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "The Successful Treatment Of Sciatica And Low Back Pain With Sports Medicine Acupuncture®",
"date": "July 24 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Treating A Quad Strain For A Super Heavyweight Powerlifter Before The KERN US Open Powerlifting Meet",
"date": "June 28 2018",
"categories": ["Knee Pain"],
"type": true
}, {
"entryTitle": "Treating A High Hamstring Strain Before A Powerlifting Competition Using Sports Medicine Acupuncture®",
"date": "June 05 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Free Acupuncture Treatments For Veterans Through The Veterans Choice Program",
"date": "June 08 2017",
"categories": ["Back Pain", "Disc Herniation", "Shoulder Pain"],
"type": true
}, {
"entryTitle": "The Treatment Of Whiplash Related Injuries With Acupuncture",
"date": "March 04 2016",
"categories": ["Disc Herniation"],
"type": false
}]
My function
const [selected, setSelected] = useState("all")
const [posts, setPosts] = useState(postData)
const filterPosts = value => {
let posts = postData
if (value !== "all") {
posts = postData.filter(post => post.categories.includes(value))
//posts = postData.filter(post => post.categories.find(post.categories === value))
}
setSelected(value)
setPosts(posts)
}
Expected results
{
"entryTitle": "What Is Sports Medicine Acupuncture?",
"date": "September 30 2015",
"categories": ["Knee Pain"],
"type": false
},
{
"entryTitle": "Treating A Quad Strain For A Super Heavyweight Powerlifter Before The KERN US Open Powerlifting Meet",
"date": "June 28 2018",
"categories": ["Knee Pain"],
"type": true
},
This entry
{
"entryTitle": "Providing Quality Care During The COVID-19 Pandemic",
"date": "March 23 2020",
"categories": null,
"type": false
}
has categories set to null. You can't do includes on it.
Fix it using optional chaining, or check the existence before:
post.categories?.includes(value)
or
post.categories && post.categories.includes(value)
In postData some of post.categories is null , so includes will not work on this
You need to check for that first and if categories available then you can check :
postData.filter(post => post.categories ? post.categories.includes("Knee Pain") : false )
OR
postData.filter(post => post.categories && post.categories.includes("Knee Pain"))
You can run the below snippet, Nope this will help you :
const data = [{
"entryTitle": "What Is Sports Medicine Acupuncture?",
"date": "September 30 2015",
"categories": ["Knee Pain"],
"type": false
}, {
"entryTitle": "Providing Quality Care During The COVID-19 Pandemic",
"date": "March 23 2020",
"categories": null,
"type": false
}, {
"entryTitle": "Correcting Severe Antalgic Posture & Gait",
"date": "May 09 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "The Successful Treatment Of Sciatica And Low Back Pain With Sports Medicine Acupuncture®",
"date": "July 24 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Treating A Quad Strain For A Super Heavyweight Powerlifter Before The KERN US Open Powerlifting Meet",
"date": "June 28 2018",
"categories": ["Knee Pain"],
"type": true
}, {
"entryTitle": "Treating A High Hamstring Strain Before A Powerlifting Competition Using Sports Medicine Acupuncture®",
"date": "June 05 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Free Acupuncture Treatments For Veterans Through The Veterans Choice Program",
"date": "June 08 2017",
"categories": ["Back Pain", "Disc Herniation", "Shoulder Pain"],
"type": true
}, {
"entryTitle": "The Treatment Of Whiplash Related Injuries With Acupuncture",
"date": "March 04 2016",
"categories": ["Disc Herniation"],
"type": false
}]
console.log(data.filter(post => post.categories ? post.categories.includes("Knee Pain") : false ))
The explanation for TypeError: Cannot read property 'includes' of null: the second entry has null categories:
{
"entryTitle": "Providing Quality Care During The COVID-19 Pandemic",
"date": "March 23 2020",
"categories": null,
"type": false
}
Perhaps you want post => post.categories!==null ? post.categories.includes(value) : false
The explanation for TypeError: false is not a function: a.find accepts a function. find will run that function on each entry of a and return the first entry which returned true. So you should use post.categories.find(category => category===value). (What you have doesn't make sense, since an array can't equal the value.)
You could check for categories first as follows:
post.categories && post.categories.includes('Back Pain')
const postData = [{
"entryTitle": "What Is Sports Medicine Acupuncture?",
"date": "September 30 2015",
"categories": ["Knee Pain"],
"type": false
}, {
"entryTitle": "Providing Quality Care During The COVID-19 Pandemic",
"date": "March 23 2020",
"categories": null,
"type": false
}, {
"entryTitle": "Correcting Severe Antalgic Posture & Gait",
"date": "May 09 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "The Successful Treatment Of Sciatica And Low Back Pain With Sports Medicine Acupuncture®",
"date": "July 24 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Treating A Quad Strain For A Super Heavyweight Powerlifter Before The KERN US Open Powerlifting Meet",
"date": "June 28 2018",
"categories": ["Knee Pain"],
"type": true
}, {
"entryTitle": "Treating A High Hamstring Strain Before A Powerlifting Competition Using Sports Medicine Acupuncture®",
"date": "June 05 2020",
"categories": ["Back Pain"],
"type": true
}, {
"entryTitle": "Free Acupuncture Treatments For Veterans Through The Veterans Choice Program",
"date": "June 08 2017",
"categories": ["Back Pain", "Disc Herniation", "Shoulder Pain"],
"type": true
}, {
"entryTitle": "The Treatment Of Whiplash Related Injuries With Acupuncture",
"date": "March 04 2016",
"categories": ["Disc Herniation"],
"type": false
}];
const filteredResult = postData.filter(post => post.categories && post.categories.includes('Back Pain'));
console.log(filteredResult);

Nested ngFor only returns last item on inner ngFor

I am trying to loop through firebase RTDB reference to retrieve a list and then use those results in a subsequent firestore query. the console logs the correct data but my code only displays the last item in the loop in the inside ngFor. Any help would be appreciated. Thanks
this.ref = firebase.database().ref('stations/');
this.ref.on('value', resp => {
this.infos = [];
this.infos = snapshotToArray(resp);
});
const snapshotToArray = snapshot => {
let returnArr = [];
snapshot.forEach(childSnapshot => {
let item = childSnapshot.val();
item.key = childSnapshot.key;
returnArr.push(item.StationtName);
let sku = item.StationtName;
this.queues = this.afs.collection('projects', ref => ref.where('station', '==', item.StationtName)).valueChanges()
});
return returnArr;
}
html:
<div *ngFor="let info of infos">
{{info}}
<div *ngFor="let queue of queues | async">
<ion-button> {{queue.SKU}}</ion-button>
</div>
</div>
json and new error:
ERROR Error: Cannot find a differ supporting object '[
{
"SKU": "908897",
"buyerEmail": "m",
"comments": "c",
"createdAt": 1550285024451,
"queue": 1,
"station": "The Warehouse",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}
]' of type 'string'. NgFor only supports binding to Iterables such as Arrays.
this.infos:
["Lathe", "Press 1", "Press 2", "Mill 1", "Mill 2", "Ready", "Plasma", "Grinding", "Grinding", "Flange shop", "the office", "The Warehouse"]
added an .subscribe() to this.queues and got the correct info logged to the console on every loop. The associated projects for each station are printed to the console. Here is one of them;
["09987", "66553", "3", "98774", "4", "987654321", "1", "6533343434343"]
these are all SKU's that are associated with each station.
Here is the subscribe code I added to get the value of the observable, now Im getting another error though:
.subscribe(data=>{
console.log(data);
this.items = data.map(function (obj) {
return obj.SKU;
});
console.log(this.items);
// this.stationArr.push(this.item);
})
The error I'm getting now is:
Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
And this in the the chrome inspector:
<!--bindings={
"ng-reflect-ng-for-of": null
}-->
current output:
Lathe
----- 908897
Press 1
----- 908897
Press 2
----- 908897
Mill 1
----- 908897
Mill 2
----- 908897
Ready
----- 908897
Plasma
----- 908897
Grinding
----- 908897
Grinding
----- 908897
Flange shop
----- 908897
the office
----- 908897
The Warehouse
----- 908897
desired output:
Lathe
----- 908897
Press 1
----- 123432,5476344
Press 2
----- empty
Mill 1
----- 0987654, 7777777, 673654
Mill 2
----- 12321
Ready
----- 909090990, 878787878, 67767
etc.
each station has a SKU associated, but my code displays the same one for each station.
json file:
[{
"id": "0rikFyAEt4Zg83sPeUNG",
"SKU": "88",
"buyerEmail": "",
"comments": "",
"createdAt": 1550297319125,
"queue": 1,
"station": "Press 1",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "1UJftXBqdmvjwJAs2XO5",
"SKU": "77777e7e7",
"buyerEmail": "b",
"comments": "c",
"createdAt": 1550291447696,
"queue": 1,
"station": "Lathe",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "1aFkV5z0JBzfii0edQCd",
"SKU": "911111111",
"buyerEmail": "matt#duhon.com",
"comments": "comment",
"createdAt": 1550286952568,
"queue": 1,
"station": "Grinding",
"stations": ["Addy"],
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "5BylWSmtH02v8oCq7T2B",
"SKU": "123456789",
"buyerEmail": "MAtts",
"comments": "comment",
"createdAt": 1550372243065,
"queue": 1,
"station": "Press 1",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "BVNaMjK5oqSslnfE6Uar",
"SKU": "11111111",
"buyerEmail": "",
"comments": "",
"createdAt": 1550290392880,
"queue": 1,
"station": "Mill",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "HvxQF4suTBaiCwpWgf9D",
"SKU": "908897",
"buyerEmail": "m",
"comments": "c",
"createdAt": 1550285024451,
"queue": 1,
"station": "The Warehouse",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "KfJ4qvVyDzVwFxIeMRzM",
"SKU": "09987",
"buyerEmail": "",
"comments": "",
"createdAt": 1550286034246,
"queue": 1,
"station": "Ready",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "MrrioE5IHpImz52qnHW5",
"SKU": "1211221",
"buyerEmail": "",
"comments": "",
"createdAt": 1550290371569,
"queue": 1,
"station": "Lathe",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "TczmkayGuWonT6SQZf6F",
"SKU": "3",
"buyerEmail": "",
"comments": "3 years old yo!",
"createdAt": 1550298020154,
"queue": 1,
"station": "Ready",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "ZspOz31o0uYT0Msull5J",
"SKU": "909987",
"buyerEmail": "matt#duhon.com",
"comments": "comment",
"createdAt": 1550286926441,
"queue": 1,
"station": "Packaging",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "hXC1uswgbW1UVTfVD96k",
"SKU": "98774",
"buyerEmail": "matt#duhon.com",
"comments": "comments",
"createdAt": 1550296878271,
"queue": 1,
"station": "Ready",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "jeR8wCiPdCwObZvajT04",
"SKU": "4",
"buyerEmail": "matt",
"comments": "comments",
"createdAt": 1550298181612,
"queue": 1,
"station": "Ready",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "lx2Hh3rpQ1rLkGHAgEzo",
"SKU": "987654321",
"buyerEmail": "yomama",
"comments": "com mints",
"createdAt": 1550296669267,
"queue": 1,
"station": "Ready",
"timeTest": "Fri Feb 15 2019",
"type": "Project"
}, {
"id": "qAYSdYYC2wxBwYDYI71T",
"SKU": "1",
"buyerEmail": "",
"comments": "",
"createdAt": 1550297026128,
"queue": 1,
"station": "Ready",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}, {
"id": "sBXhW6lPaYtUn4fz5Gsf",
"SKU": "6533343434343",
"buyerEmail": "MAtt",
"comments": "Comment",
"createdAt": 1550372086063,
"queue": 1,
"station": "Ready",
"timeTest": "Sat Feb 16 2019",
"type": "Project"
}]
As per you code check this Demo code where you can see the nested *ngFor
<ul>
<li *ngFor="let info of infos">{{info}}
<ol *ngFor="let queue of queues | async">{{queue.SKU}}</ol>
</li>
</ul>

showing File System Structure using JSON in angularJS

I need a JSON array which contains a sample file system with corresponding attributes(type, name, size, created, modified, last_accessed etc.). Then I want to plot it as a web file system in a tree structure.
So, how will my JSON be look like & how should I make that tree in angularJS?
Editions:
I made JSON as -
{
"data" : {
"path":[
"My Files",
"Documents"
],
"data" : [
{
"name": "Work Documents",
"type": "folder",
"owner": "me",
"size": "",
"modified": "May 24, 2017",
"opened": "May 22, 2017",
"created": "May 22, 2017",
"extention": "",
"location": "My Files > Documents",
"offline": true,
"children" : [
{
"name": "Public Documents",
"type": "folder",
"owner": "public",
"size": "",
"modified": "July 8, 2015",
"opened": "July 8, 2015",
"created": "July 8, 2015",
"extention": "",
"location": "My Files > Documents",
"offline": true
},
{
"name": "Ongoing projects",
"type": "document",
"owner": "Emily Bennett",
"size": "1.2 Mb",
"modified": "July 8, 2015",
"opened": "July 8, 2015",
"created": "July 8, 2015",
"extention": "",
"location": "My Files > Documents",
"offline": true,
"preview": "assets/images/etc/sample-file-preview.jpg"
},
{
"name": "Shopping list",
"type": "document",
"owner": "Emily Bennett",
"size": "980 Kb",
"modified": "July 8, 2015",
"opened": "July 8, 2015",
"created": "July 8, 2015",
"extention": "",
"location": "My Files > Documents",
"offline": true,
"preview": "assets/images/etc/sample-file-preview.jpg"
}
]
},
{
"name": "Private Documents",
"type": "folder",
"owner": "me",
"size": "",
"modified": "July 8, 2015",
"opened": "July 8, 2015",
"created": "July 8, 2015",
"extention": "",
"location": "My Files > Documents",
"offline": true
}
]
}
}
But how can I iterate it in html ? I'm currently displaying it, but unable to understand how to show 'Children' on click of folder. This is my html -
<tr ng-repeat="file in vm.data | filter:global.search" ng-click="vm.select(file)" ng-class="{'selected' : vm.selected === file}">
<td class="file-icon">
<i class="icon-{{file.type}}"></i>
</td>
<td class="name">{{file.name}}</td>
<td class="type" hide show-gt-sm>{{file.type}}</td>
<td class="owner" hide-xs>{{file.owner}}</td>
<td class="size" hide-xs>{{file.size === '' ? '-': file.size}}</td>
<td class="last-modified" hide show-gt-md>{{file.modified}}</td>
<td class="show-details" hide-gt-md>
<md-button class="md-icon-button sidenav-toggle" ng-click="vm.toggleDetails(file)" aria-label="Details" translate translate-attr-aria-label="FM.DETAILS">
<md-icon md-font-icon="icon-information-outline"></md-icon>
</md-button>
</td>
</tr>
You can create a Json like this if it fullfil your requirements. Suppose you have a root dir of name root and it has child dirs books and videos.
Var root = {
dirName: "root",
metadata: {
size: " 1 gb",
type: "dir",
last_modified: " 24 may 2017",
// Other attributes
},
children: [
{
dirName: "books",
metadata: {
size: " 10 mb",
type: "dir",
last_modified: " 24 may 2017",
// Other attributes
},
Children:{}
},
{
dirName: "videos",
metadata: {
size: " 10 mb",
type: "dir",
last_modified: " 24 may 2017",
// Other attributes
}
}
]
}
You can now modify it as per your needs
I used this to display tree structure - https://github.com/eu81273/angular.treeview

export json to xls doc in java/ js

I'm trying to export json data into an Excel file. My json is not consistent which is why I have problem because the excel mapping is all scattered and the columns are messed up. Here is a sample JSON I'm working on:
[
{
"path": "/conte/nt",
"title": "First",
"date": "January 14, 2015 8:59:57 PM EST"
},
{
"path": "/content/o",
"title": "Third Annual",
"date": "January 14, 2015 8:59:57 PM EST"
},
{
"path": "/co/en",
"title": "Motivating Factors",
"date": "January 14, 2015 8:59:57 PM EST"
},
{
"path": "/con/ent",
"title": "Meeting",
"description": "test",
"date": "January 14, 2015 8:59:57 PM EST",
"key": "xyz, abc"
}
]

Categories