We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS Platform: mac
Node.js Version: v14.15.5
ThinkJS Version: 3.2.10
// your code here
// your error message here
// your detail description
#529
The text was updated successfully, but these errors were encountered:
看了一下,似乎没有支持。不过我觉得你可以使用 afterSelect 和 afterFind 钩子自行实现。类似下面这样
afterSelect
afterFind
module.exports = class extends think.Model { camelize(obj) { for(const k in obj) { if(!k.includes('_')) { continue; } const newKey = k.replace(/([-_][a-z])/ig, ($1) => { return $1.toUpperCase() .replace('_', ''); }); obj[newKey] = obj[k]; delete obj[k]; } return obj; } afterSelect(data) { return data.map(item => this.camelize(item)); } afterFind(data) { return this.camelize(data); } }
Sorry, something went wrong.
看了一下,似乎没有支持。不过我觉得你可以使用 afterSelect 和 afterFind 钩子自行实现。类似下面这样 module.exports = class extends think.Model { camelize(obj) { for(const k in obj) { if(!k.includes('_')) { continue; } const newKey = k.replace(/([-_][a-z])/ig, ($1) => { return $1.toUpperCase() .replace('_', ''); }); obj[newKey] = obj[k]; delete obj[k]; } return obj; } afterSelect(data) { return data.map(item => this.camelize(item)); } afterFind(data) { return this.camelize(data); } }
if (!k.includes('_')) { continue; // 使用 continue 不然会出现null }
No branches or pull requests
DESC
ENV
OS Platform: mac
Node.js Version: v14.15.5
ThinkJS Version: 3.2.10
code
// your code here
error message
more description
// your detail description
#529
The text was updated successfully, but these errors were encountered: