JavaScript 代码示例:根据后端数据进行前端返显
JavaScript 代码示例:根据后端数据进行前端返显
1. 后端逻辑:
function createAuthObject(authKey, authVals) {
return {
authScope: 1,
authKey,
authVals
};
}
if (isCheckboxOrganization) {
params.extInfOptionAuths.push(createAuthObject('RealOrganization.resourceId', selectOrganizationIds));
}
if (isCheckboxTenant) {
params.extInfOptionAuths.push(createAuthObject('RealTenant.resourceId', selectFilterTenantIds));
}
if (isCheckboxBusiness) {
params.extInfOptionAuths.push(createAuthObject('webTenants.resourceId', selectedTenantIds));
params.extInfOptionAuths.push(createAuthObject('RealBusiness.resourceId', selectedBusinessIds));
}
if (isCheckboxArea) {
params.extInfOptionAuths.push(createAuthObject('ResourcePool.type', selectAreaIdList));
}
if (isCheckboxPool) {
params.extInfOptionAuths.push(createAuthObject('ResourcePool.resourceId', filtSelectedPoolIds));
}
if (isSelectPod) {
params.extInfOptionAuths.push(createAuthObject('webPoolIds.resourceId', selectedPoolIds));
params.extInfOptionAuths.push(createAuthObject('Pod.resourceId', selectedPodIds));
}
2. 前端逻辑:
根据这个逻辑,可以推出以下逻辑来进行数据的返显:
// 根据后端返回的数据,判断是否勾选了相应的复选框
const isCheckboxOrganization = params.extInfOptionAuths.some(authObj => authObj.authKey === 'RealOrganization.resourceId');
const isCheckboxTenant = params.extInfOptionAuths.some(authObj => authObj.authKey === 'RealTenant.resourceId');
const isCheckboxBusiness = params.extInfOptionAuths.some(authObj => authObj.authKey === 'RealBusiness.resourceId');
const isCheckboxArea = params.extInfOptionAuths.some(authObj => authObj.authKey === 'ResourcePool.type');
const isCheckboxPool = params.extInfOptionAuths.some(authObj => authObj.authKey === 'ResourcePool.resourceId');
const isSelectPod = params.extInfOptionAuths.some(authObj => authObj.authKey === 'Pod.resourceId');
// 根据后端返回的数据,获取对应的值
const selectOrganizationIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'RealOrganization.resourceId')?.authVals || [];
const selectFilterTenantIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'RealTenant.resourceId')?.authVals || [];
const selectedTenantIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'webTenants.resourceId')?.authVals || [];
const selectedBusinessIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'RealBusiness.resourceId')?.authVals || [];
const selectAreaIdList = params.extInfOptionAuths.find(authObj => authObj.authKey === 'ResourcePool.type')?.authVals || [];
const filtSelectedPoolIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'ResourcePool.resourceId')?.authVals || [];
const selectedPoolIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'webPoolIds.resourceId')?.authVals || [];
const selectedPodIds = params.extInfOptionAuths.find(authObj => authObj.authKey === 'Pod.resourceId')?.authVals || [];
// 根据上述的判断和获取的值,进行相应的返显操作
if (isCheckboxOrganization) {
// 对应的复选框被勾选,根据selectOrganizationIds进行相应的返显操作
}
if (isCheckboxTenant) {
// 对应的复选框被勾选,根据selectFilterTenantIds进行相应的返显操作
}
if (isCheckboxBusiness) {
// 对应的复选框被勾选,根据selectedTenantIds和selectedBusinessIds进行相应的返显操作
}
if (isCheckboxArea) {
// 对应的复选框被勾选,根据selectAreaIdList进行相应的返显操作
}
if (isCheckboxPool) {
// 对应的复选框被勾选,根据filtSelectedPoolIds进行相应的返显操作
}
if (isSelectPod) {
// 对应的复选框被勾选,根据selectedPoolIds和selectedPodIds进行相应的返显操作
}
请根据实际需求进行具体的返显操作。
原文地址: https://www.cveoy.top/t/topic/pdQv 著作权归作者所有。请勿转载和采集!