I'm trying to use yeoman to take this JSON file:
{
"models": {
"user": {
"properties": [
{
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"id": "number"
}
]
}
}
}
And turn it into something like:
Class User {
name : string
surname : string
id : number
}
Would it be possible to do some form of looping in the template? Here's what I have in mind...
export class <%= entityName %> extends Model {
<% forEach (property in props) { %>
<%= property.name %> : <% property.type %>;
<% } %>
}
I'm trying to use yeoman to take this JSON file:
{
"models": {
"user": {
"properties": [
{
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"id": "number"
}
]
}
}
}
And turn it into something like:
Class User {
name : string
surname : string
id : number
}
Would it be possible to do some form of looping in the template? Here's what I have in mind...
export class <%= entityName %> extends Model {
<% forEach (property in props) { %>
<%= property.name %> : <% property.type %>;
<% } %>
}
Share
Improve this question
edited Mar 10, 2016 at 19:24
David
asked Mar 10, 2016 at 19:15
DavidDavid
16.1k26 gold badges117 silver badges160 bronze badges
2 Answers
Reset to default 9The template language can run any JS code. So just use normal for
loop or iterations methods on arrays (arr.forEach()
)
export class <%= entityName %> extends Model {
<% for (property of props) { %>
<%= property.name %> : <% property.type %>;
<% } %>
}
Yeoman is using ejs as template engine. Visit their website for more information on the supported features.
I dont think you can use that kind of looping in the template. What you could do is to have a helpermethod in your script file to generate the content from your json file into a variable, and then add that variable to your template.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744383372a4571540.html
评论列表(0条)