From f4648510fd1612ca3fcb03cf032327c2bbdae38a Mon Sep 17 00:00:00 2001 From: Kokomi <102026640+yoimiya-kokomi@users.noreply.github.com> Date: Tue, 9 May 2023 11:00:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Data.forEach=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E6=96=B0=E7=89=88Miao-Yunzai?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Data.js | 24 ++++++++++++++++++++++++ models/MysApi.js | 1 + 2 files changed, 25 insertions(+) diff --git a/components/Data.js b/components/Data.js index 17194119..9a7cdfa8 100644 --- a/components/Data.js +++ b/components/Data.js @@ -239,6 +239,30 @@ let Data = { } }, + async forEach (data, fn) { + if (lodash.isArray(data)) { + for (let idx = 0; idx < data.length; idx++) { + let ret = fn(data[idx], idx) + if (ret instanceof Promise) { + ret = await ret + } + if (ret === false) { + break + } + } + } else if (lodash.isPlainObject(data)) { + for (const idx in data) { + let ret = fn(data[idx], idx) + if (ret instanceof Promise) { + ret = await ret + } + if (ret === false) { + break + } + } + } + }, + // 循环字符串回调 eachStr: (arr, fn) => { if (lodash.isString(arr)) { diff --git a/models/MysApi.js b/models/MysApi.js index 1cbe8c60..4b2f32ae 100644 --- a/models/MysApi.js +++ b/models/MysApi.js @@ -6,6 +6,7 @@ export default class MysApi { this.e = e this.mysInfo = mysInfo this.ckInfo = mysInfo.ckInfo + this.ckUser = mysInfo.ckUser this.uid = uid e.targetUser = this.targetUser e.selfUser = this.selfUser