recursionGet(valueId) { console.log(this.logAssets) let setValues=this.logAssets let id = null; for (let index = 0; index < setValues.length; index += 1) { if (setValues[index].id === valueId) { id = setValues[index].name; break; } if (setValues[index].children instanceof Array && setValues[index].children.length > 0) { const text = recursionGet(setValues[index].children, valueId); if (text) return text; } } return id; },的正确写法
时间: 2024-02-10 11:14:20 浏览: 26
这段代码中有一个递归函数 `recursionGet`,但是在递归调用时,函数名没有加上 `this` 关键字,导致会出现 undefined 的错误。下面是正确的写法:
```
recursionGet(valueId) {
console.log(this.logAssets);
let setValues = this.logAssets;
let id = null;
for (let index = 0; index < setValues.length; index += 1) {
if (setValues[index].id === valueId) {
id = setValues[index].name;
break;
}
if (setValues[index].children instanceof Array && setValues[index].children.length > 0) {
const text = this.recursionGet(setValues[index].children, valueId);
if (text) {
return text;
}
}
}
return id;
},
```
在递归调用时,需要加上 `this` 关键字,以便正确找到函数。
相关问题
/** * 递归函数 * @param setValues 树型数据 * @param valueId 查找的id */ function recursionGet(setValues, valueId) { let value = null; for (let index = 0; index < setValues.length; index += 1) { if (setValues[index].value === valueId) { value = setValues[index].label; break; } if (setValues[index].children instanceof Array && setValues[index].children.length > 0) { const text = recursionGet(setValues[index].children, valueId); if (text) return text; } } return value; } // 调用 const data =recursionGet(list,301) console.log(data) // 输出 行政 用vue写出来
<template>
<div>
<span>{{ department }}</span>
</div>
</template>
<script>
export default {
name: "DepartmentSelector",
props: {
list: {
type: Array,
required: true
},
valueId: {
type: Number,
required: true
}
},
data() {
return {
department: null
};
},
mounted() {
this.department = this.recursionGet(this.list, this.valueId);
},
methods: {
recursionGet(setValues, valueId) {
let value = null;
for (let index = 0; index < setValues.length; index += 1) {
if (setValues[index].value === valueId) {
value = setValues[index].label;
break;
}
if (
setValues[index].children instanceof Array &&
setValues[index].children.length > 0
) {
const text = this.recursionGet(
setValues[index].children,
valueId
);
if (text) return text;
}
}
return value;
}
}
};
</script>
imageview的imageview.this.mMatrix.setValues(toMatrixValue);怎样改成textureview
在TextureView中,同样可以使用Matrix来对绘制内容进行矩阵变换,只不过其操作对象不再是ImageView的mMatrix,而是TextureView的SurfaceTexture。因此,可以将代码修改为以下形式:
```java
TextureView textureView = findViewById(R.id.texture_view);
SurfaceTexture surfaceTexture = textureView.getSurfaceTexture();
Matrix matrix = new Matrix();
matrix.setValues(toMatrixValue);
surfaceTexture.setTransform(matrix);
```
其中,getSurfaceTexture()方法可以获取TextureView的SurfaceTexture对象,通过SurfaceTexture.setTransform()方法可以对绘制内容进行矩阵变换。在上面的代码中,我们创建了一个新的Matrix对象,并将其设置为toMatrixValue对应的矩阵,然后将其应用到SurfaceTexture上,从而实现了TextureView中的矩阵变换。
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.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)