Last active
December 27, 2017 14:00
-
-
Save wisetc/e44846c91c10a58a003ddfe8f1fde117 to your computer and use it in GitHub Desktop.
Promise.all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| ... | |
| methods: { | |
| ... | |
| validateRowForm(form, error, rules) { | |
| return new Promise((resolve, reject) => { | |
| new schema(rules).validate(form, (errors, fields) => { | |
| if (fields) { | |
| for (let k in fields) { | |
| error[k] = { | |
| isError: true, | |
| message: fields[k][0].message | |
| }; | |
| } | |
| } | |
| let valid = fields ? false : true; | |
| resolve(valid); | |
| }); | |
| }); | |
| }, | |
| validateAllRowForm() { | |
| return new Promise((resolve, reject) => { | |
| let promises = this.data.map(row => this.validateRowForm(row.__form__, row.__error__, this.rules)) | |
| Promise.all(promises).then(values => { | |
| resolve(values.every(valid => valid)) | |
| }) | |
| }) | |
| }, | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment