问题描述
我得到了这个config.json文件:
"signs_table": {
"id_field": "dummy_id_field_name","prop" : "dummy_prop_name"
...
}
此文件包含用于存储在数据库中的大量表的大量配置。每个表都有不同的字段名称,但是我的代码的配置对于每个表都是相同的(一个ID字段名称,不同的属性字段,但是当然字段名称在表之间是不同的。)
因此,在我的代码中,我正在获取一个数据对象,并且希望能够将其分解为动态命名的属性(来自配置),如下所示:
const { dummy_id_field_name,dummy_prop_name} = this.props.data
但这是硬编码方式。我想基于配置文件加载命名属性。 像:
const IdField = config.get("signs_table").id_field // this will retrieve the actual field name from config.json I want to be able to pass it through the destructuring operation
const PropField = config.get("signs_table").prop
const { IdField,PropField } = data
config.get("signs_table")
行是来自管理我的config.json文件的类方法,它基本上可以检索属性。
到目前为止,我发现了这种有用的方法: ES6 — How to destructure from an object with a string key?
但这对我没有帮助,因为我需要先从配置文件中检索字段名称...
有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)