UNPKG

ts-api-core

Version:

Nodejs api framework core

34 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetObjectArrayItemCondition = exports.BaseMerageCondition = void 0; /** 自动数据合并条件处理器 */ class BaseMerageCondition { } exports.BaseMerageCondition = BaseMerageCondition; /** * 自动数据合并条件 - 将源数据作为一个对象数组,从此数组中选择1个匹配的数据项,参数:`数组对象字段名`, `当前数据字段名` */ class GetObjectArrayItemCondition extends BaseMerageCondition { constructor(srcField, valueField) { super(); this.srcField = srcField; this.valueField = valueField; } execute(src, value) { const fieldValue = value ? value[this.valueField] : undefined; if (src && value && this.srcField && fieldValue) { const items = Array.isArray(src) ? src : [src]; let i = 0; while (i < items.length) { const item = items[i]; if (item[this.srcField] === fieldValue) { return item; } i = i + 1; } } return undefined; } } exports.GetObjectArrayItemCondition = GetObjectArrayItemCondition; //# sourceMappingURL=merage.condition.js.map