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

How get get previous node value in 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 presentfield 对象中时

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

喜欢这个

{{#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}}