angular - 我们可以在订阅方法中循环吗?
问题描述
this.schoolCareerStore = this.SchoolPageStateStore.select('School_Sections_Text').subscribe((data)=>{
console.log("school_Career_store",data)
this.test2=data.Video
console.log(this.test2)
for(let value of this.test2)
{
if(value.type='youtube')
{
this.test1=value.number
this.test==`https://www.youtube.com/embed/${this.test1}`;
console.log('this is the url',this.test)
}
}
});
//当我尝试时.......那没有执行......如果有办法可以做到请赐教??提前致谢
解决方案
我认为以下更改会帮助您:
this.schoolCareerStore =
this.SchoolPageStateStore.select('School_Sections_Text').subscribe((data)=>{
this.test2=data.Video;
for(let value of this.test2)
{
if(value.type=='youtube')
{
this.test1=value.number;
this.test==`https://www.youtube.com/embed/${this.test1}`;
}
}
});
在你需要的条件下,==
或===
。==
将只检查值(而不是类型)。但===
会检查值和类型。更改if(value.type='youtube')
为if(value.type=='youtube')
.
希望这可以帮助。
推荐阅读
- reactjs - 反应方法绑定
- c++ - 如何将用户为板中的行和列选择的内容
- ios - 以编程方式呈现全屏
- wordpress - 将 ACF 字段添加到 REST API 以进行递归发布
- bash - 如何将 stdout 和 stderr 分别传送到两个不同的进程,同时让它们出现在终端中?
- python - pandas 1.1.5 和 1.3.4 之间的哪些变化改变了 set_index / reset_index 过程?
- c++ - 不允许出现错误 C2139 未定义类 - 在 MFC 应用程序中使用 xaml 岛时
- python - 为什么 scipy.stats.uniform.pdf 这么慢?
- swiftui - 是否可以从 viewModel 订阅视图的焦点状态?
- nrwl-nx - nx - 为生成的 package.json 配置 main/module