Drawing dust using json . How to draw the key data in dust

144 Views Asked by At

This is the data:

 var json=   [
        {
            "key1": "val1"
        },
        {
            "key2": "val2"
        },
        {
            "key3": "val3"
        }
    ]

How can I draw the data both 'key1', 'key2','key3' and 'val1' ,'val2' ,'val3' to draw it in dust?

If the object is like

var address =   {
    "a": "addressr",
    "c": "city",
    "s": "state",
    "z": "zip" 
}

and if I know the keys already I can draw like {address.a} to get the address.

1

There are 1 best solutions below

0
On

I found a way to solve my problem for right now (please explain if there is another direct way)

var newjson = [];
for(var key in json)
 {
    var arr     =   json[key]; 
    var value   =   arr[Object.keys(arr)[0]]; 
    var keys    =   Object.keys(arr)[0] ;
    var len         =       newjson.length;
    newjson[len]    =       {
                "k":keys,
                "v":value
                    }   
 }

and i padd newjson to the dust file and draw as

{#newjson}
{k}-----{v}
{/newjson}

the output will be

key1------val1 key2------val2 key13------val3