雷峰
雷峰
  • 发布:2022-05-11 10:55
  • 更新:2022-05-11 10:55
  • 阅读:947

【uni-admin管理系统】schema2code生成代码有BUG的解决方案

分类:uniCloud

用过schema2code生成管理系统页面的人,大概率会碰到这样一种情况吧:
比如下面这个是schema文件中一个字段的规则

  "foreignKey": "goods-list._id",  
  "enum": {  
       "collection": "goods-list",  
       "where": "type==10",  
      "field": "name as text,_id as value"  
  }

此时直接生成的list文件会存在无法正确显示正确的枚举值。
每次如果都要自己去手动改,就很麻烦。而且如果后续这个表新增了字段,再次生成后,又会破坏原本改好的内容。
而且schema2code插件作者一直也没更新了,这个生成代码的槽点不止这一个地方。

解决方案:

将上面的代码规则替换成如下:

"componentForEdit": {  
                "name": "uni-data-checkbox",  
                "props": {  
                    "collection": "goods-list",  
                    "where": "type==20",  
                    "field": "name as text,_id as value"  
                }  
            },  
            "componentForShow": {  
                "name": "daxiang-query-first",  
                "props": {  
                    "collection": "goods-list",  
                    "where": "type==20",  
                    "valueKey": "_id",  
                    "showField": "name"  
                }  
            }

此代码是使用了daxiang-query-first这个插件,解决在列表中显示枚举值。
插件详见:
daxiang-query-first

2 关注 分享
l***@qq.com 天爱天

要回复文章请先登录注册