ReactJS SourceBinding,FieldList 저장여부
추천0 비추천 0
페이지 정보
작성자 바밤바 작성일 2023-10-13 16:34 조회 217회 댓글 0건제품 버전 : 16.1
컨트롤 이름 : SourceBinding,FieldList
본문
관련링크
안녕하세요 제가 코드레벨에서
1. fieldList를 동적으로 생성하고 동적으로 생성
2. fieldList의 sourceBinding도 진행
3. fieldList에서 항목을 드래그해서 셀에 붙여넣으면 bindingPath가 입력됩니다.
4. fieldList Tab을 닫은후에 해당 bindingPath에 항목에 데이터를 입력하면 bindingPath가 입력된 곳에 value들이 모두 바뀝니다.
이렇게 모든 과정을 실행후 저장 시점에 동적으로 생성된 fieldList와 binding될 데이터와 bindingPath 모두 저장하는 방법이 있나요??
더해서 fieldList와 binding될 데이터를 따로 뺄수있는 메소드도 존재하는지 궁금합니다.
아래는 Api 호출후 성공적으로 호출 했을때 실행되는 로직입니다.
onSuccess(data) {
const jsonData = JSON.parse(data.data.data.jsondata);
const selectedKeys = JSON.parse(data.data.data.value);
const findNodes = (node: any, keys: any) => {
if (
keys.includes(node.key) ||
node.children.some((child: any) => findNodes(child, keys))
) {
return {
...node,
children: node.children
.map((child: any) => findNodes(child, keys))
.filter(Boolean),
};
}
return null;
};
// select Keys값을 기준으로 데이터를 추출.
const reconstructedData = jsonData
.map((node: any) => findNodes(node, selectedKeys))
.filter(Boolean);
// 최종적으로 가공된 데이터 result.
const result = processJsonData(reconstructedData, {
properties: {},
type: 'object',
});
// Sheet Binding Filed List 설정
designer?.setData('treeNodeFromJSON', JSON.stringify(result));
// Sheet Binding Data 가공
const transformData = (inputData: any) => {
const transformedData: any = {};
for (const key in inputData) {
// 각 키에 대한 데이터 가져오기
const keyData = inputData[key];
// 키 이름을 소문자로 변경하고 transformedData에 추가
const formattedKey = key.charAt(0).toUpperCase() + key.slice(1);
console.log(formattedKey);
transformedData[formattedKey] = processKeyData(keyData);
}
return transformedData;
};
// Sheet Binding 데이터 가공
const processKeyData = (keyData: any) => {
if (typeof keyData === 'object' && !Array.isArray(keyData)) {
const processedData: any = {};
if (keyData.properties) {
for (const subKey in keyData.properties) {
processedData[subKey] = processKeyData(
keyData.properties[subKey],
);
}
return processedData;
}
// Return an empty string if there are no properties.
return '';
}
// Return an empty string for the last value.
return '';
};
// sourceBinding 할 데이터
const bindData = transformData(result.properties);
// sourceBinding 할 데이터 설정
const source = new GC.Spread.Sheets.Bindings.CellBindingSource(
bindData,
);
const sheet = workbook?.getActiveSheet();
// sourceBinding 실행
sheet?.setDataSource(source);
},
댓글목록
등록된 댓글이 없습니다.