Does Dust.js provide a way to reference an object key/value by keywords "key" and "value"? -
Does Dust.js provide a way to reference an object key/value by keywords "key" and "value"? -
i want utilize dust.js client template engine. have info json this:
var info = { "foo": [{ "somekey": "somevalue", "otherkey": "othervalue" }, { "somekey": "somevalue", "otherkey": "othervalue" }], "bar": [{ "somekey": "somevalue", "otherkey": "othervalue" }, { "somekey": "somevalue", "otherkey": "othervalue" }] } i not know in advance uppermost object keys - not know foo , bar keys, can value.
so, need iterate through json keywords key , value. in pseudo-code:
{% for(key, value) in info %} {key}: {value} {% /for %} i know dust.js has {#section/} loop through object. again, have provide key name:
{#extradata} {! within section, dust looks values within extradata object !} within section, value of name is: {name}{~n} {/extradata} and not know extradata name in advance.
so, dust.js provide way reference object keys/values key , value keywords?
dust not provide built-in iteration on objects.
however, can add together {@iterate} helper type of iteration.
you can @ https://www.npmjs.com/package/dustmotes-iterate
example usage:
data: { obj: {a:"a", b:"b", c:"c" } } {@iterate key=obj} {$key}:{$value} {$type} {/iterate} output: a:a string b:b string c:c string dust.js
Comments
Post a Comment