如何获得胡子中的先前节点值

时间:2016-07-29 11:56:49

标签: templates mustache

我有一个对象,它有多个对象

fields:[
  {
     safeName: 'status',
     accessorName: 'Status',
     type: {name: 'String', doc: 'String', code: '\'String\''},
     field: {type: 'string', description: 'pet status in the store', enum: ['available', 'pending', 'sold']}
  },
  {

     safeName: 'code',
     accessorName: 'Code',
     type: {name: 'NSInteger', doc: 'NSInteger', code: '\'NSInteger\'' },
     field: {type: 'integer', format: 'int32'}
  },
  ... 
]

我需要检查枚举值

输出应为

字段

中存在enum

instance.status = Order.Status(rawValue: (sourceDictionary["status"] as? String) ?? "")

enum is not present对象中的field

instance.code = Decoders.decodeOptional(clazz: NSInteger.self, source: sourceDictionary["code"])

1 个答案:

答案 0 :(得分:0)

喜欢这个

{{#fields}}{{#field}}
  {{#description}}
    instance.{{safeName}} = Order.Status(rawValue: (sourceDictionary["{{safeName}}"] as? String) ?? "")
  {{/description}} 
  {{^description}}
    instance.{{safeName}} = Decoders.decodeOptional(clazz: {{#type}}{{type.name}}{{/type}}.self, source: sourceDictionary["code"])
  {{/description}
{{/field}}{{/fields}}