GithubHelp home page GithubHelp logo

valparams's People

Contributors

d780 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zpc10

valparams's Issues

如何验证 日期格式?

date: { type: 'date', required: false, defValue: null, desc: '收集日期' }

校验后的时间会被格式化成

date :Fri Jan 22 2021 08:00:00 GMT+0800 (China Standard Time)

请问应该怎么处理?

验证数组的时候出来的是'[object Object]',而不是数组的值

待验证的表单
save2server---form>

{
    "id":"29",
    "wordsList":[
        {
            "originTxt":"1, determines  
决心 
确定
",
            "en":"determines",
            "lineOne":"1, determines  ",
            "explain":"决心 
确定",
            "showExplain":true
        },
        {
            "originTxt":"
2, access  ['ækses]
接入

n. 进入;使用权;通路 
vt. 使用;存取;接近",
            "en":"access",
            "lineOne":"2, access  ['ækses]",
            "explain":"接入
n. 进入;使用权;通路 
vt. 使用;存取;接近",
            "showExplain":true
        }
    ]
}

验证代码

async addWords() {
  console.log('addWords------>')
  let { ctx, app } = this;
  // 参数验证
  ctx.validate({
      id: { type: 'string', required: true, range: { min: 1, max: 30 }, desc: '必须要有id' },
      wordsList: {
          type: 'array',
          desc: '数组错误',
      },
  });
  let { id, wordsList, } = ctx.request.body;

  console.log( wordsList)
  console.log(typeof (wordsList[0]))
}

console.log结果

addWords------>
[ '[object Object]', '[object Object]' ]
string

如果不用验证的时候是正常的
验证代码

async addWords() {
    console.log('addWords------>')
    let { ctx, app } = this;
    // // 参数验证
    // ctx.validate({
    //     id: { type: 'string', required: true, range: { min: 1, max: 30 }, desc: '必须要有id' },
    //     wordsList: {
    //         type: 'array',
    //         desc: '数组错误',
    //         // items: {
    //         //     type: 'object',
    //         //     properties: {
    //         //         en: {
    //         //             type: 'string',
    //         //         },
    //         //         explain: {
    //         //             type: 'string',
    //         //         },
    //         //         lineOne: {
    //         //             type: 'string',
    //         //         },
    //         //         originTxt: {
    //         //             type: 'string',
    //         //         },
    //         //         showExplain: {
    //         //             type: 'bool',
    //         //         },
    //         //     },
    //         // }
    //     },
    // });
    let { id, wordsList, } = ctx.request.body;

    console.log( wordsList)
    console.log(typeof (wordsList[0]))
}

console.log结果

addWords------>
[
  {
    originTxt: '1, determines  \n决心 \n确定\n',
    en: 'determines',
    lineOne: '1, determines  ',
    explain: '决心 \n确定',
    showExplain: true
  },
  {
    originTxt: "\n2, access  ['ækses]\n接入\n\nn. 进入;使用权;通路 \nvt. 使用;存取;接近",
    en: 'access',
    lineOne: "2, access  ['ækses]",
    explain: '接入\nn. 进入;使用权;通路 \nvt. 使用;存取;接近',
    showExplain: true
  }
]
object

请问要怎么做才能正确返回数组对象呢?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.