- 31
- 0
递归获取树形结构会报以下bug,目前也就四五层的样子,只要展开节点的时候就报下面的错误了,我试过不递归的话,能展开第一层,但是一递归就报错
代码:
search2(rows:any, parentId:any) {
let result:any = [];
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
if (!!parentId) {
if (row.ParentId == parentId) {
result.push(row);
}
} else {
if (!!row.ParentId && row.ParentId == 0) {
result.push(row);
}
}
}
return result;
}
createChildTree2(rows:any, parentTree:any) {
let nodeList:any = [];
let drs = this.search2(rows, parentTree.id);
let childrenData:Array<Model.treeGridModel>=[]
for (let i = 0; i < drs.length; i++) {
let tree = {
id:0,
code:0,
name:"",
status:"",
remark:"",
parentId:0,
_checked:false,
isChecked:false,
children:childrenData,
selected:false,
expanded:false,
load:false,
parent:parent,
level:1,
isShow:true,
spaceHtml:''
};
let dr = drs[i];
tree.id=dr["JobPositionId"]
tree.code=dr["JobPositionId"]
tree.name=dr["JobPositionName"]
tree.status=dr["JobPositionName"]
tree.remark=dr["JobPositionName"]
tree.parentId=dr["ParentId"]
tree._checked=false
tree.isChecked=false
tree.children=this.createChildTree2(rows, tree);
tree.selected=false
tree.expanded=false
tree.load=false
tree.parent=parent
tree.level=1
tree.isShow=true
tree.spaceHtml=""
nodeList.push(tree);
}
return nodeList;
}
async getPostTypeList(){
let rs=await jobService.getJobList()
let treeList:any = [];
let rows=rs!.data.data
let childrenData:Array<Model.treeGridModel>=[]
let parent:object={}
let drs = this.search2(rows, '');
for (let i = 0; i < drs.length; i++) {
let dr = drs[i];
let tree = {
id:0,
code:0,
name:"",
status:"",
remark:"",
parentId:0,
_checked:false,
isChecked:false,
children:childrenData,
selected:false,
expanded:false,
load:false,
parent:parent,
level:1,
isShow:true,
spaceHtml:''
};
tree.id=dr["JobPositionId"]
tree.code=dr["JobPositionId"]
tree.name=dr["JobPositionName"]
tree.status=dr["JobPositionName"]
tree.remark=dr["JobPositionName"]
tree.parentId=dr["ParentId"]
tree._checked=false
tree.isChecked=false
tree.children=this.createChildTree2(rows, tree);
tree.selected=false
tree.expanded=false
tree.load=false
tree.parent=parent
tree.level=1
tree.isShow=true
tree.spaceHtml=""
treeList.push(tree);
}
return treeList
}
vue.runtime.esm.js:588 [Vue warn]: Error in render: "RangeError: Maximum call stack size exceeded"
warn @ vue.runtime.esm.js:588
logError @ vue.runtime.esm.js:1732
globalHandleError @ vue.runtime.esm.js:1727
handleError @ vue.runtime.esm.js:1716
Vue._render @ vue.runtime.esm.js:4534
updateComponent @ vue.runtime.esm.js:2783
get @ vue.runtime.esm.js:3137
run @ vue.runtime.esm.js:3214
flushSchedulerQueue @ vue.runtime.esm.js:2976
(anonymous) @ vue.runtime.esm.js:1832
flushCallbacks @ vue.runtime.esm.js:1753
vue.runtime.esm.js:1736 RangeError: Maximum call stack size exceeded
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966)
at _traverse (vue.runtime.esm.js:1966) - 共 0 条
- 全部回答
-
森屿暮歌 普通会员 1楼
在 Vue.js 中,你可能会遇到类型错误,特别是当你尝试在 TypeScript 中使用数组的子数组时。这通常是因为 TypeScript 不支持数组的递归操作。以下是一些可能的解决方案:
- 使用箭头函数:
```typescript let arr = [1, 2, 3, 4, 5];
// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument arr.map((item) => item + 1);// This will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr2 = [...arr, 1, 2, 3, 4, 5];// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr3 = [...arr, ...arr, 1, 2, 3, 4, 5];// And this will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr4 = [...arr, ...arr, ...arr, 1, 2, 3, 4, 5]; ```- 使用循环:
```typescript let arr = [1, 2, 3, 4, 5];
// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument arr.map((item) => item + 1);// This will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr2 = [...arr, 1, 2, 3, 4, 5];// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr3 = [...arr, ...arr, 1, 2, 3, 4, 5];// And this will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr4 = [...arr, ...arr, ...arr, 1, 2, 3, 4, 5];// And this will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument ```- 使用生成器函数:
```typescript let arr = [1, 2, 3, 4, 5];
// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr2 = [...arr, 1, 2, 3, 4, 5];// This will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr3 = [...arr, ...arr, 1, 2, 3, 4, 5];// And this will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr4 = [...arr, ...arr, ...arr, 1, 2, 3, 4, 5];// And this will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument ```- 使用数组的
reduce方法:
```typescript let arr = [1, 2, 3, 4, 5];
// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr2 = [...arr, 1, 2, 3, 4, 5];// This will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr3 = [...arr, ...arr, 1, 2, 3, 4, 5];// And this will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr4 = [...arr, ...arr, ...arr, 1, 2, 3, 4, 5];// And this will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr5 = [...arr, ...arr, ...arr, 1, 2, 3, 4, 5];// And this will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument ```- 使用模板字符串:
```typescript let arr = [1, 2, 3, 4, 5];
// This will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr2 =[${arr[0]}, ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}];// This will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr3 =[${arr[0]}, ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}];// And this will also work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr4 =[${arr[0]}, ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}];// And this will work, but TypeScript will report an error // because the
mapfunction expects an array as the second argument // Instead, you can use the spread operator to pass the array as the first argument const arr5 =[${arr[0]}, ${arr[1]}, ${arr[2]}, ${arr[3]}, ${arr[4]}]; ```以上就是解决在 Vue.js 中出现类型错误的一些方法。你可以根据自己的需求选择合适的方法。
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
