Closed devarajc closed 8 years ago
Here's a quick example of how to write a custom helper to pick a random item from an array:
var helpers = {
color: function (options) {
var colors = ['blue', 'red', 'green'];
return colors[Math.floor(Math.random() * (colors.length))];
}
};
var template = '{ "background": {{color}} }';
var result = dummyjson.parse(template, {helpers: helpers});
This is quite a common scenario so I plan to make it a little easier to implement in the next major release version.
Its worked fine and Thank you so much
This has changed slightly since v1.0.0, for more information and an example see https://github.com/webroo/dummy-json#array-based-helpers
Hi ,
I want to know about in dummy json how to get an random value from customize array. Let my array would be var color = ["blue" , "red", "green"]
Thanks