egg-validate插件对嵌套数据能做验证吗?

Created on 5 Jan 2018  ·  4Comments  ·  Source: eggjs/egg

 integralEvents:  {
        baseIntegral: '12',                       
        userName:   [
           '5a06b428e806d466f7e118dc',            
           '5a06b428e806d466f7e118d4'
        ],          
         name: '1212',                             
         content: '12',                            
         createTime: '2018-01-02T16:00:00.000Z',   
         revocation: '0'
   }

egg-validate能验证者这种嵌套的数据,比如验证userName是不是数组,我看了文档,没这方面的介绍。
我用点语法也不行。

"userIntegral.userName": "array"

Most helpful comment

const rule = {
  baseIntegral: 'string',
  userName: {
    type: 'array',
    itemType: {type:'string', format: ...}
  },
....
};

or

const rule = {
  integralEvents: {
    type: 'object',
    rule: {
       baseIntegral: 'string',
       userName: {
           type: 'array',
            itemType: {type:'string', format: ...}
         .....
        },
    }
  }
}

All 4 comments

const rule = {
  baseIntegral: 'string',
  userName: {
    type: 'array',
    itemType: {type:'string', format: ...}
  },
....
};

or

const rule = {
  integralEvents: {
    type: 'object',
    rule: {
       baseIntegral: 'string',
       userName: {
           type: 'array',
            itemType: {type:'string', format: ...}
         .....
        },
    }
  }
}

还有这种操作,@zhangming0305 谢谢。

不是这么写的吗?itemType怎么会是个对象?

const rule = {
baseIntegral: 'string',
userName: {
type: 'array',
itemType: 'string' ,
rule: {
}
},
....
};

Was this page helpful?
0 / 5 - 0 ratings