首页 > 解决方案 > 我们可以在订阅方法中循环吗?

问题描述

 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)
            }
        }

    });

//当我尝试时.......那没有执行......如果有办法可以做到请赐教??提前致谢

标签: angularngrx

解决方案


我认为以下更改会帮助您:

 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').

希望这可以帮助。


推荐阅读