简介

本文通过连接器和单选搜索对明细表进行赋值/获取等操作
场景:在需要获取另一张表的明细数据作为单选数据,并进行赋值绑定。

案例及步骤

(1)创建原数据表

(2)配置连接器查询

注:原数据的明细表 OBJ_ID 跟表单的 ID 是匹配的。

(3)创建需要数据的表单

关联数据的实际存储的关联字段值要为主键,后面查询需要。

编辑连接器配置

将另一张表明细的字段填充到指定组件字段(类型需要一致)

(4)通过属性联动触发单选搜索。

代码参考

// 说明是谁调用事件,方便排查链路
const owner = 'test';
// 获取事件总线
const subjectEventBus = configs.utils?.getSubjectEventBus?.();
// 调用搜索事件,
subjectEventBus.publishEvent({ owner, eventName: 'form:onSearch' , data: { name: '模糊查询的值,和code二选一', code: '精确查询的值,和name二选一', formCode: '目标字段的formCode', attrCode: '目标字段的attrCode', afterSearchOperate: 'firstOption或者noValue, 搜索后连接器判断noValue的话,不会执行连接器配置的联动,firstOption暂时没支持', id: '如果目标在明细表中,需要行id', index: '如果目标在明细表中,需要行序号'  }});

案例代码

const {context,utils} = configs;
const bg = context.getFormData().ASSOCIATED_BG;
let list = context.getFormData().COST_BREAKDOWN_TABLE2;

// 说明是谁调用事件,方便排查链路
const owner = 'testBG';
// 获取事件总线
const subjectEventBus = utils?.getSubjectEventBus?.();
// 调用搜索事件,
// configs.utils.message.info(bg)
for(let i in list){
    console.log("==============")
    console.log(list[i])
    subjectEventBus.publishEvent({ 
        owner, eventName: 'form:onSearch' , 
        data: { 
        // 获取 BG 的 ID
            name: bg,
            // 明细表编码
            formCode: 'COST_BREAKDOWN_TABLE2',
            //具体组件编码
            attrCode: 'COST_NAME', 
            afterSearchOperate: 'noValue',
            id: list[i].id,
            index: i
        },
    });
}

效果

作者:tz_docs  创建时间:2024-06-26 16:47
最后编辑:tz_docs  更新时间:2025-06-26 10:44