let expandedName = ref(""); function transTree(list: any, data: any) { const treeData: any = []; list.forEach((item: any) => { if (!item.parent_id || item.parent_id == "") { expandedName.value = item.name; treeData.push(item); } const children = list.filter(function (data: any, index: any) { return data.parent_id === item.guid; }); if (!children.length) { return; } if (!Number.isInteger(Number(children[0].name))) { item.disabled = true; } item.children = children; }); return treeData; } // 权限树checked的触发 async function batchReportProgressList() { let nodes = proxy.$refs.treeRef.getCheckedNodes(); if (nodes == "") { batchReportTableData.value = []; return; } let newNodes: any = []; nodes.forEach((node: any) => { if (!node.children) { newNodes.push(node.guid); } }); batchReportFrom.value.guids = newNodes.toString(); let { data: res }: any = await proxy.$http.post( "/bimServer/component_schedule/componentScheduleByGuids", batchReportFrom.value ); if (res.status !== 200) { return proxy.$message.error(res.msg); } batchReportTableData.value = res.data; }
时间: 2024-01-11 14:05:53 浏览: 46
这段代码是使用 TypeScript 编写的,主要实现了一个树形结构的数据转换和一个权限树的勾选触发的异步函数。其中,`transTree`函数将一个扁平的数据列表转换成树形结构,并记录下第一个节点的名称;`batchReportProgressList`函数则是根据勾选的节点的GUID,向后端发起请求获取相关数据,并将其赋值给`batchReportTableData`。在勾选节点时,如果该节点没有子节点,则将其GUID加入到`newNodes`数组中。
相关问题
const projectionTransforms: Ref<any> = ref(null);用JavaScript怎么写
在JavaScript中使用Vue 3中的Composition API,可以这样写:
```javascript
import { ref } from 'vue';
const projectionTransforms = ref(null);
```
或者直接使用ES6的语法,不使用Vue 3的Composition API,可以这样写:
```javascript
const projectionTransforms = null;
```
react 组件如何共用 let advancedLightingService: any = new AdvancedLightingService();
在 React 组件中共用一个服务对象,可以通过以下方式实现:
1. 将服务对象实例化并存储在一个独立的模块中,然后在需要使用服务的组件中引入该模块,以获取对服务对象的访问权限。
例如,在一个名为 `services.ts` 的独立模块中,定义 `AdvancedLightingService` 类并导出一个实例:
```
class AdvancedLightingService {
// ...
}
export const advancedLightingService = new AdvancedLightingService();
```
然后,在需要使用服务的 React 组件中直接引入该模块:
```
import { advancedLightingService } from './services'
function MyComponent() {
// 使用 advancedLightingService 对象...
}
```
2. 将服务对象传递给组件实例,以使组件实例能够访问服务对象。
例如,在一个名为 `App.tsx` 的组件中,创建 `AdvancedLightingService` 实例并将其作为属性传递给 `MyComponent`:
```
import { AdvancedLightingService } from './services';
import MyComponent from './MyComponent';
function App() {
const advancedLightingService = new AdvancedLightingService();
return (
<div>
<MyComponent advancedLightingService={advancedLightingService} />
</div>
);
}
```
然后,在 `MyComponent` 组件中,可以通过 `props` 属性获取服务对象:
```
function MyComponent(props) {
const { advancedLightingService } = props;
// 使用 advancedLightingService 对象...
}
```
以上两种方式都可以实现在 React 组件中共用一个服务对象,具体使用哪种方式取决于具体场景和项目需求。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)