{
"Petition to file": [
{
"description": "fileing description",
"period": "30 days",
"fees": "500"
}
],
"Appearing before inspection": [
{
"description": "Appearence Description",
"period": "10 days",
"fees": "1500"
}
],
"Passing orders for a recording of statements": [
{
"description": "passing order description",
"period": "50 days",
"fees": "1000"
}
],
"Hearing of petition": [
{
"description": "Hearing of petition description",
"period": "55 days",
"fees": "2000"
}
],
"Decree of petition": [
{
"description": "decreeof description",
"period": "70 days",
"fees": "5000"
}
]
}
How to get the values of nested child headings. It is dynamic content .Also i need to fetch the values of nested objects that is period,fess,description . I'm using typescript program that is in angular cli
Patricio Vargas
5,60014 gold badges57 silver badges107 bronze badges
asked Nov 21, 2019 at 6:08
Maravarman Manoharan
1691 silver badge11 bronze badges
-
2did you attempt anything at all ?Kunal Mukherjee– Kunal Mukherjee2019年11月21日 06:10:24 +00:00Commented Nov 21, 2019 at 6:10
-
2There's no such thing as a "JSON Object"Andreas– Andreas2019年11月21日 06:19:21 +00:00Commented Nov 21, 2019 at 6:19
-
The point is the title(example:Petition to file) of nested object will be dynamic by server response .Maravarman Manoharan– Maravarman Manoharan2019年11月21日 06:19:28 +00:00Commented Nov 21, 2019 at 6:19
-
use Object.keys to get the dynamic keys and map them into an arrayKunal Mukherjee– Kunal Mukherjee2019年11月21日 06:21:57 +00:00Commented Nov 21, 2019 at 6:21
3 Answers 3
here is complete working example StackBlitz Link, Your main logic of traversing dynamic object entries is...
ngOnInit(){
Object.keys(this.datafromDatabase).forEach(data =>{
this.datafromDatabase[data].map(key =>{
this.data.push(key)
});
})
}
Your Template file is...
<div *ngFor="let key of data">
{{key.description}}
</div>
<div>
{{data |json}}
</div>
answered Nov 21, 2019 at 7:16
Gaurang Dhorda
3,4072 gold badges24 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
var something = consts['Petition to file'];
usually thats the way to get the values inside keys
so now the new variable something =
[
{
"description": "fileing description",
"period": "30 days",
"fees": "500"
}
]
now if u want description
var descriptionVariable = consts['description'];
so descriptionVariabe's value is fileing description
Erik Philips
54.9k11 gold badges133 silver badges158 bronze badges
Comments
let list = {
"Petition to file": [
{
"description": "fileing description",
"period": "30 days",
"fees": "500"
}
],
"Appearing before inspection": [
{
"description": "Appearence Description",
"period": "10 days",
"fees": "1500"
}
],
"Passing orders for a recording of statements": [
{
"description": "passing order description",
"period": "50 days",
"fees": "1000"
}
],
"Hearing of petition": [
{
"description": "Hearing of petition description",
"period": "55 days",
"fees": "2000"
}
],
"Decree of petition": [
{
"description": "decreeof description",
"period": "70 days",
"fees": "5000"
}
]
}
for (let [key, value] of Object.entries(list)) {
console.log(key);
console.log(value);
}
Use Object.entries
answered Nov 21, 2019 at 6:45
Saurabh Yadav
3,3861 gold badge12 silver badges21 bronze badges
Comments
lang-js