yaml中的一个值的多个键 [英] multiple keys for one value in yaml

查看:822
本文介绍了yaml中的一个值的多个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对相同的值使用不同的键?

Is it possible to use different keys for the same value?

[activerecord, activemodel]: 'test'

我希望得到与此相同的结果:

I expect the same result as with this:

activerecord: 'test'
activemodel: 'test'

推荐答案

这不起作用,因为YAML允许您指定任何类型的键,所以

That doesn't work because YAML allows you to specify keys of any type, so

[activerecord, activemodel]: 'test'

是具有单个键的映射,序列为[activerecord, activemodel],其值为'test'.

is a mapping with a single key, the sequence [activerecord, activemodel] whose value is 'test'.

相反,您可以使用锚点/别名:

Instead, you can use an anchor/alias:

activerecord: &my_value 'test'
activemodel: *my_value

但是,无法将两个键都附加到一个键/值对中的单个值上.

However, there's no way of attaching both keys to the single value in one key/value pair.

这篇关于yaml中的一个值的多个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆