Array inside JSON data output | ionic 2


#1

Hi,

I have my app all working fine with all the data coming from a JSON file. The problem is i need an array inside my JSON data

this is an example of what I want to do…

"id":"1",
        "crafting":{
                "input[0]":"8x Cobblestone",
                "input[1]":"2x Wool",
                "input[2]":"4x Wood",
        },
"id":"2",
        "crafting":{
                "input[0]":"8x Cobblestone",
                "input[1]":"2x Wool",
        },
"id":"3",
        "crafting":{
                "input[0]":"8x Cobblestone",
                "input[1]":"2x Wool",
                "input[2]":"4x Wood",
                "input[3]":"1x Torch",
        },

Currently the output is

<h1>{{items.crafting.input}}</h1>

I don’t know how to go about duplicating the H1 tag based on how many input there are, any ideas?


#2

Write a function that transforms the object into an array, and attach it to however you are getting the data (probably via map on an Observable from Http). Then use ngFor in the template to loop across it.